luci-base: luci.js: fix sortedKeys() ordering
authorJo-Philipp Wich <jo@mein.io>
Tue, 9 Feb 2021 23:02:59 +0000 (00:02 +0100)
committerJo-Philipp Wich <jo@mein.io>
Tue, 9 Feb 2021 23:08:27 +0000 (00:08 +0100)
Chrome does not properly sort arrays when the sort function returns boolean
results, in contrast to Firefox which does.

Fix the issue by returning a numerical result instead.

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

modules/luci-base/htdocs/luci-static/resources/luci.js

index 2ec96dd67262698c6c894e413edcac75f62a323e..c0e8b15a56ba50ce05f9efb8ab11d046619723c5 100644 (file)
                        }).filter(function(e) {
                                return (e[1] != null);
                        }).sort(function(a, b) {
-                               return (a[1] > b[1]);
+                               if (a[1] < b[1])
+                                       return -1;
+                               else if (a[1] > b[1])
+                                       return 1;
+                               else
+                                       return 0;
                        }).map(function(e) {
                                return e[0];
                        });