Commit 18b6c323 authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

Force NetworkConfig.securityType_ to be an enum, not a string

When we converted network_config.js to use == instead of ===, we broke
some subtle logic when using <network-config-select> with enum values:

The <option> children of the <select> element will always have a string
value, even if the value is set to a number. Thus the data binding will
quietly replace the enums with strings.

Thus was fine when using == (since "2" == 2 in JS) but breaks with ===.

Since securityType_ is the only place where we use network-config-select
with an enum, the simplest fix is to force it to an enum in
updateSecurity_().

If we use network-config-select for any more enums, we should fix it
to do the conversion if the items are numbers and not strings.

Bug: 1046149
Change-Id: Iacdf4f45296483311566ab1b0748d6947ca1429b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2027067Reviewed-by: default avatarJon Mann <jonmann@chromium.org>
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736540}
parent 5fcc73e8
......@@ -190,8 +190,9 @@ Polymer({
/**
* Security value, used for Ethernet and Wifi and to detect when Security
* changes.
* @private {!chromeos.networkConfig.mojom.SecurityType|undefined}
* changes. NOTE: the <select> element might set this to a string, see
* crbug.com/1046149.
* @private {!chromeos.networkConfig.mojom.SecurityType|string|undefined}
*/
securityType_: Number,
......@@ -375,7 +376,8 @@ Polymer({
// Allow securityType_ to be set externally (e.g. in tests).
if (mojoType === mojom.NetworkType.kWiFi &&
this.securityType_ !== undefined) {
managedProperties.typeProperties.wifi.security = this.securityType_;
managedProperties.typeProperties.wifi.security =
/**@type{!mojom.SecurityType}*/ (this.securityType_);
}
this.managedProperties_ = managedProperties;
this.mojoType_ = mojoType;
......@@ -832,6 +834,13 @@ Polymer({
return;
}
const type = this.mojoType_;
// Force |securityType_| to an enum value when the <select> element sets it
// to a string. See crbug.com/1046149 for details.
if (typeof (this.securityType_) === 'string') {
this.securityType_ =
/** @type{!chromeos.networkConfig.mojom.SecurityType}*/ (
Number.parseInt(/** @type{string}*/ (this.securityType_), 10));
}
const security = this.securityType_;
if (type === mojom.NetworkType.kWiFi) {
this.configProperties_.typeConfig.wifi.security = security;
......
......@@ -106,8 +106,9 @@ Polymer({
},
/**
* @param {string|!chromeos.networkConfig.mojom.NetworkCertificate} item
* @return {string}
* @param {string|number|!chromeos.networkConfig.mojom.NetworkCertificate}
* item
* @return {string|number}
* @private
*/
getItemValue_(item) {
......@@ -116,7 +117,7 @@ Polymer({
item)
.hash;
}
return /** @type {string} */ (item);
return /** @type {string|number}*/ (item);
},
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment