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

Unified Diff: abp2blocklist.js

Issue 29336525: Issue 3584 - Work around WebKit uppercase ID matching bug (Closed)
Patch Set: Use [id="Whatever"] syntax Created Feb. 17, 2016, 1:42 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: abp2blocklist.js
diff --git a/abp2blocklist.js b/abp2blocklist.js
index 71d227f3e66f9a9f9c044409840967523982d923..0ee872a96a8bdd3cd7ed33a0f49fe91b96fe54e2 100644
--- a/abp2blocklist.js
+++ b/abp2blocklist.js
@@ -254,6 +254,60 @@ function hasNonASCI(obj)
return false;
}
+function attributeSyntaxForIDs(selector)
+{
+ if (selector.indexOf("#") == -1)
+ return selector;
+
+ // First we figure out where all the IDs are
+ let sep = "";
+ let IDstart = null;
+ let IDpositions = [];
+ for (let i = 0; i < selector.length; i++)
+ {
+ let chr = selector[i];
+
+ if (chr == "\\") // ignore escaped characters
+ i++;
+ else if (chr == sep) // don't split within quoted text
+ sep = ""; // e.g. [attr=","]
+ else if (sep == "")
+ {
+ if (chr == '"' || chr == "'")
+ sep = chr;
+ else if (IDstart == null) // look for the start of an ID
+ {
+ if (chr == "#")
+ IDstart = i;
+ }
+ else if (chr < "0" && chr != "-" ||
Sebastian Noack 2016/02/17 14:22:19 I'd find the logic here easier to read if you'd ch
kzar 2016/02/17 15:35:03 Done.
+ chr > "9" && chr < "A" ||
+ chr > "Z" && chr != "_" && chr < "a" ||
+ chr > "z" && chr < "\x80") // look for the end of the ID
+ {
+ IDpositions.push({start: IDstart, end: i});
+ IDstart = null;
+ }
+ }
+ }
+
+ if (IDpositions.length == 0)
+ return selector;
+
+ // Now replace them all with the [id="someID"] form
+ let newSelector = "";
+ let position = 0;
+ for (let ID of IDpositions)
+ {
+ newSelector += selector.substring(position, ID.start);
+ newSelector += '[id="' + selector.substring(ID.start + 1, ID.end) + '"]';
+ position = ID.end;
+ }
+ newSelector += selector.substring(position);
+
+ return newSelector;
+}
+
function logRules()
{
let rules = [];
@@ -286,10 +340,16 @@ function logRules()
{
while (selectors.length)
{
+ let selector = selectors.splice(0, selectorLimit).join(", ");
+
+ // As of Safari 9.0 element IDs are matched as lowercase. We work around
+ // this by converting to the attribute format [id="elementID"]
+ selector = attributeSyntaxForIDs(selector);
+
addRule({
trigger: {"url-filter": matchDomain},
action: {type: "css-display-none",
- selector: selectors.splice(0, selectorLimit).join(", ")}
+ selector: selector}
});
}
});
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld