luci-app-firewall: fix creating multiple networks from zone network selector
authorJo-Philipp Wich <jo@mein.io>
Mon, 1 Mar 2021 07:54:26 +0000 (08:54 +0100)
committerJo-Philipp Wich <jo@mein.io>
Mon, 1 Mar 2021 07:56:25 +0000 (08:56 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 5d528da29f3b03deba0144c85d862e1e4468ff25)

applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/zones.js

index b2f9b81a9ba17811b726e7eb363f1be029793c31..6bb366e37e12270fb3d5214c7e35fa721cff4dac 100644 (file)
@@ -170,19 +170,24 @@ return view.extend({
                };
                o.write = function(section_id, formvalue) {
                        var name = uci.get('firewall', section_id, 'name'),
-                           cfgvalue = this.cfgvalue(section_id);
+                           cfgvalue = this.cfgvalue(section_id),
+                           oldNetworks = L.toArray(cfgvalue),
+                           newNetworks = L.toArray(formvalue);
 
-                       if (typeof(cfgvalue) == 'string' && Array.isArray(formvalue) && (cfgvalue == formvalue.join(' ')))
+                       oldNetworks.sort();
+                       newNetworks.sort();
+
+                       if (oldNetworks.join(' ') == newNetworks.join(' '))
                                return;
 
                        var tasks = [ firewall.getZone(name) ];
 
                        if (Array.isArray(formvalue))
-                               for (var i = 0; i < formvalue.length; i++) {
-                                       var netname = formvalue[i];
-                                       tasks.push(network.getNetwork(netname).then(function(net) {
+                               for (var i = 0; i < newNetworks.length; i++) {
+                                       var netname = newNetworks[i];
+                                       tasks.push(network.getNetwork(netname).then(L.bind(function(netname, net) {
                                                return net || network.addNetwork(netname, { 'proto': 'none' });
-                                       }));
+                                       }, this, netname)));
                                }
 
                        return Promise.all(tasks).then(function(zone_networks) {