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

Unified Diff: lib/filterComposer.js

Issue 29328834: Issue 3163 - Adapt "Block element" functionality for a change in Chrome dealing with "\0" in CSS se… (Closed)
Patch Set: Created Oct. 5, 2015, 1:30 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 | « no previous file | qunit/tests/cssEscaping.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterComposer.js
===================================================================
--- a/lib/filterComposer.js
+++ b/lib/filterComposer.js
@@ -22,6 +22,10 @@
let {defaultMatcher} = require("matcher");
let {RegExpFilter} = require("filterClasses");
+function isValidString(s) {
+ return s && s.indexOf("\0") == -1;
+}
+
function escapeChar(chr)
{
let code = chr.charCodeAt(0);
@@ -119,19 +123,21 @@
if (filters.length == 0 && !isFrameWhitelisted(page, frame, RegExpFilter.typeMap.ELEMHIDE))
{
// Generate CSS selectors based on the element's "id" and "class" attribute
- if (details.id)
+ if (isValidString(details.id))
selectors.push("#" + escapeCSS(details.id));
- if (details.classes.length > 0)
- selectors.push(details.classes.map(c => "." + escapeCSS(c)).join(""));
+
+ let classes = details.classes.filter(isValidString);
+ if (classes.length > 0)
+ selectors.push(classes.map(c => "." + escapeCSS(c)).join(""));
// If there is a "src" attribute, specifiying a URL that we can't block,
// generate a CSS selector matching the "src" attribute
- if (details.src)
+ if (isValidString(details.src))
selectors.push(escapeCSS(details.tagName) + "[src=" + quoteCSS(details.src) + "]");
// As last resort, if there is a "style" attribute, and we couldn't generate
// any filters so far, generate a CSS selector matching the "style" attribute
- if (details.style && selectors.length == 0 && filters.length == 0)
+ if (isValidString(details.style) && selectors.length == 0 && filters.length == 0)
selectors.push(escapeCSS(details.tagName) + "[style=" + quoteCSS(details.style) + "]");
// Add an element hiding filter for each generated CSS selector
« no previous file with comments | « no previous file | qunit/tests/cssEscaping.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld