diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-06-02 11:54:42 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-06-03 09:51:09 +0200 |
commit | e35041e0a8edcf039d62a74cbc5e0f4043d04029 (patch) | |
tree | 286ee5af3cbf9b716baf68c36e47739c55b2fda9 /modules | |
parent | c7b7b42cd3840cfd67f412191578a8659eb63c87 (diff) |
luci-base: network.js: sorting fixes
Ensure that sort callbacks consistently return [-N .. 0 .. +N] values
instead of just true/false.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/luci-base/htdocs/luci-static/resources/network.js | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/network.js b/modules/luci-base/htdocs/luci-static/resources/network.js index 40f9eaaa5b..b1dfcfd77c 100644 --- a/modules/luci-base/htdocs/luci-static/resources/network.js +++ b/modules/luci-base/htdocs/luci-static/resources/network.js @@ -101,6 +101,15 @@ var _init = null, _protocols = {}, _protospecs = {}; +function strcmp(a, b) { + if (a > b) + return 1; + else if (a < b) + return -1; + else + return 0; +} + function getProtocolHandlers(cache) { return callNetworkProtoHandlers().then(function(protos) { /* Register "none" protocol */ @@ -552,7 +561,7 @@ function ifnameOf(obj) { } function networkSort(a, b) { - return a.getName() > b.getName(); + return strcmp(a.getName(), b.getName()); } function deviceSort(a, b) { @@ -563,7 +572,7 @@ function deviceSort(a, b) { if (weightA != weightB) return weightA - weightB; - return a.getName() > b.getName(); + return strcmp(a.getName(), b.getName()); } function formatWifiEncryption(enc) { @@ -1421,7 +1430,7 @@ Network = baseclass.extend(/** @lends LuCI.network.prototype */ { rv.push(this.lookupWifiNetwork(wifiIfaces[i]['.name'])); rv.sort(function(a, b) { - return (a.getID() > b.getID()); + return strcmp(a.getID(), b.getID()); }); return rv; @@ -1522,12 +1531,7 @@ Network = baseclass.extend(/** @lends LuCI.network.prototype */ { if (a.metric != b.metric) return (a.metric - b.metric); - if (a.interface < b.interface) - return -1; - else if (a.interface > b.interface) - return 1; - - return 0; + return strcmp(a.interface, b.interface); }); return rv; @@ -1974,7 +1978,9 @@ Hosts = baseclass.extend(/** @lends LuCI.network.Hosts.prototype */ { rv.push([mac, hint]); } - return rv.sort(function(a, b) { return a[0] > b[0] }); + return rv.sort(function(a, b) { + return strcmp(a[0], b[0]); + }); } }); @@ -3341,7 +3347,10 @@ WifiDevice = baseclass.extend(/** @lends LuCI.network.WifiDevice.prototype */ { modestr = ''; hwmodes.sort(function(a, b) { - return (a.length != b.length ? a.length > b.length : a > b); + if (a.length != b.length) + return a.length - b.length; + + return strcmp(a, b); }); modestr = hwmodes.join(''); |