Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/elemHide.js

Issue 30002601: Issue 7284 - Move CSS escaping to createStyleSheet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Updated addressing most comments Created Feb. 13, 2019, 4:33 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/content/elemHideEmulation.js ('k') | lib/filterClasses.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/elemHide.js
===================================================================
--- a/lib/elemHide.js
+++ b/lib/elemHide.js
@@ -472,29 +472,41 @@
// this could still lead to some selectors not working on Chromium, but it is
// highly unlikely.
// See issue #6298 and https://crbug.com/804179
for (let i = 0; i < selectors.length; i += selectorGroupSize)
yield selectors.slice(i, i + selectorGroupSize);
}
/**
+ * Escapes curly braces to prevent CSS rule injection.
+ *
+ * @param {string} selector
+ * @returns {string}
+ */
+function escapeSelector(selector)
+{
+ return selector.replace("{", "\\7B ").replace("}", "\\7D ");
+}
+
+/**
* Creates an element hiding CSS rule for a given list of selectors.
*
* @param {Array.<string>} selectors
* @returns {string}
*/
function createRule(selectors)
{
let rule = "";
for (let i = 0; i < selectors.length - 1; i++)
- rule += selectors[i] + ", ";
+ rule += escapeSelector(selectors[i]) + ", ";
Manish Jethani 2019/02/14 04:40:21 Performance-wise this additional code seems to be
- rule += selectors[selectors.length - 1] + " {display: none !important;}\n";
+ rule += escapeSelector(selectors[selectors.length - 1]) +
+ " {display: none !important;}\n";
return rule;
}
/**
* Creates an element hiding CSS style sheet from a given list of selectors.
* @param {Array.<string>} selectors
* @returns {string}
« no previous file with comments | « lib/content/elemHideEmulation.js ('k') | lib/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld