From 9503acc2bf6e024a0c9e971b7c460a1f82f20eb9 Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 2 Oct 2017 17:54:04 +0300 Subject: [PATCH] styleSectionsEqual() order of sections should be identical Thus we account for the case of multiple sections matching the same URL because the order of rules is part of cascading --- background/storage.js | 25 +++++++------------------ content/install.js | 25 +++++++------------------ 2 files changed, 14 insertions(+), 36 deletions(-) diff --git a/background/storage.js b/background/storage.js index 31e617ee..c34f4bee 100644 --- a/background/storage.js +++ b/background/storage.js @@ -586,13 +586,9 @@ function styleSectionsEqual({sections: a}, {sections: b}) { if (a.length !== b.length) { return false; } - const checkedInB = []; - return a.every(sectionA => b.some(sectionB => { - if (!checkedInB.includes(sectionB) && propertiesEqual(sectionA, sectionB)) { - checkedInB.push(sectionB); - return true; - } - })); + // order of sections should be identical to account for the case of multiple + // sections matching the same URL because the order of rules is part of cascading + return a.every((sectionA, index) => propertiesEqual(sectionA, b[index])); function propertiesEqual(secA, secB) { for (const name of ['urlPrefixes', 'urls', 'domains', 'regexps']) { @@ -613,17 +609,10 @@ function styleSectionsEqual({sections: a}, {sections: b}) { } function arrayMirrors(array1, array2) { - for (const el of array1) { - if (array2.indexOf(el) < 0) { - return false; - } - } - for (const el of array2) { - if (array1.indexOf(el) < 0) { - return false; - } - } - return true; + return ( + array1.every(el => array2.includes(el)) && + array2.every(el => array1.includes(el)) + ); } } diff --git a/content/install.js b/content/install.js index 35d3b616..25bbd62b 100644 --- a/content/install.js +++ b/content/install.js @@ -285,13 +285,9 @@ function styleSectionsEqual({sections: a}, {sections: b}) { if (a.length !== b.length) { return false; } - const checkedInB = []; - return a.every(sectionA => b.some(sectionB => { - if (!checkedInB.includes(sectionB) && propertiesEqual(sectionA, sectionB)) { - checkedInB.push(sectionB); - return true; - } - })); + // order of sections should be identical to account for the case of multiple + // sections matching the same URL because the order of rules is part of cascading + return a.every((sectionA, index) => propertiesEqual(sectionA, b[index])); function propertiesEqual(secA, secB) { for (const name of ['urlPrefixes', 'urls', 'domains', 'regexps']) { @@ -312,17 +308,10 @@ function styleSectionsEqual({sections: a}, {sections: b}) { } function arrayMirrors(array1, array2) { - for (const el of array1) { - if (array2.indexOf(el) < 0) { - return false; - } - } - for (const el of array2) { - if (array1.indexOf(el) < 0) { - return false; - } - } - return true; + return ( + array1.every(el => array2.includes(el)) && + array2.every(el => array1.includes(el)) + ); } }