luci-mod-network: fix sort operations
authorJo-Philipp Wich <jo@mein.io>
Fri, 8 Jul 2022 14:03:14 +0000 (16:03 +0200)
committerJo-Philipp Wich <jo@mein.io>
Mon, 3 Apr 2023 11:19:56 +0000 (13:19 +0200)
Ensure to return [-1, 0, 1] from the sort callback instead of [0, 1]
which fails in non-FF browsers.

Fixes: #5859
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 3a6f37f9df68c4055f9adc792e0fd4c5a1a1bf66)

modules/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js

index 18078cd9bd776ab5cd846a99cedf3ff40d12de4f..e5376d07c878f8096b3ab26bea0760940fa9ace2 100644 (file)
 
 var isReadonlyView = !L.hasViewPermission() || null;
 
+function strcmp(a, b) {
+       if (a < b)
+               return -1;
+
+       if (a > b)
+               return 1;
+
+       return 0;
+}
+
 function count_changes(section_id) {
        var changes = ui.changes.changes, n = 0;
 
@@ -535,7 +545,7 @@ return view.extend({
                                var protocols = network.getProtocols();
 
                                protocols.sort(function(a, b) {
-                                       return a.getProtocol() > b.getProtocol();
+                                       return strcmp(a.getProtocol(), b.getProtocol());
                                });
 
                                o = s.taboption('general', form.DummyValue, '_ifacestat_modal', _('Status'));
@@ -1253,7 +1263,7 @@ return view.extend({
 
                s.cfgsections = function() {
                        var sections = uci.sections('network', 'device'),
-                           section_ids = sections.sort(function(a, b) { return a.name > b.name }).map(function(s) { return s['.name'] });
+                           section_ids = sections.sort(function(a, b) { return strcmp(a.name, b.name) }).map(function(s) { return s['.name'] });
 
                        for (var i = 0; i < netDevs.length; i++) {
                                if (sections.filter(function(s) { return s.name == netDevs[i].getName() }).length)