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

Unified Diff: include.postload.js

Issue 5945877571043328: Issue 705 - Generate element hiding instead request blocking filters for non-HTTP URLs (Closed)
Patch Set: Rebased Created Oct. 23, 2014, 11:15 a.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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include.postload.js
===================================================================
--- a/include.postload.js
+++ b/include.postload.js
@@ -381,6 +381,13 @@
selectorList.push(selector);
};
+ var addSelectorFromAttribute = function(element, attribute)
+ {
+ var value = element.getAttribute(attribute);
+ if (value)
+ addSelector(element.localName + "[" + attribute + '="' + value.replace(/"/g, '\\"') + '"]');
Wladimir Palant 2014/10/24 17:56:55 This isn't a sufficient escaping approach. First o
Sebastian Noack 2014/10/30 16:36:24 The attribute name is hard-coded in the calling co
+ };
+
if (elementId)
addSelector("#" + elementId);
@@ -396,8 +403,13 @@
if (url)
{
- clickHideFilters.push(url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"));
- selectorList.push('[src="' + elt.getAttribute("src") + '"]');
+ if (/^https?:/i.test(url))
+ {
+ clickHideFilters.push(url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"));
+ selectorList.push('[src="' + elt.getAttribute("src") + '"]');
+ }
+ else
+ addSelectorFromAttribute(elt, "src");
}
// Show popup
@@ -408,8 +420,8 @@
unhighlightElement(currentElement);
// as last resort, create a filter based on inline styles
- if (clickHideFilters.length == 0 && elt.hasAttribute("style"))
- addSelector(elt.localName + '[style="' + elt.getAttribute("style").replace(/"/g, '\\"') + '"]');
+ if (clickHideFilters.length == 0)
+ addSelectorFromAttribute(elt, "style");
// Highlight the elements specified by selector in yellow
highlightElements(selectorList.join(","));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld