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 |