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

Delta Between Two Patch Sets: abp2blocklist.js

Issue 29336525: Issue 3584 - Work around WebKit uppercase ID matching bug (Closed)
Left Patch Set: Addressed nit I missed before Created Feb. 17, 2016, 3:25 p.m.
Right Patch Set: Addressed further feedback Created Feb. 17, 2016, 3:33 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 "use strict"; 1 "use strict";
2 2
3 let readline = require("readline"); 3 let readline = require("readline");
4 let punycode = require("punycode"); 4 let punycode = require("punycode");
5 let tldjs = require("tldjs"); 5 let tldjs = require("tldjs");
6 let filterClasses = require("./adblockplus.js"); 6 let filterClasses = require("./adblockplus.js");
7 7
8 let typeMap = filterClasses.RegExpFilter.typeMap; 8 let typeMap = filterClasses.RegExpFilter.typeMap;
9 9
10 const selectorLimit = 5000; 10 const selectorLimit = 5000;
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 // First we figure out where all the IDs are 259 // First we figure out where all the IDs are
260 let sep = ""; 260 let sep = "";
261 let start = null; 261 let start = null;
262 let positions = []; 262 let positions = [];
263 for (let i = 0; i < selector.length; i++) 263 for (let i = 0; i < selector.length; i++)
264 { 264 {
265 let chr = selector[i]; 265 let chr = selector[i];
266 266
267 if (chr == "\\") // ignore escaped characters 267 if (chr == "\\") // ignore escaped characters
268 i++; 268 i++;
269 else if (chr == sep) // don't split within quoted text 269 else if (chr == sep) // don't match IDs within quoted text
270 sep = ""; // e.g. [attr=","] 270 sep = ""; // e.g. [attr="#Hello"]
271 else if (sep == "") 271 else if (sep == "")
272 { 272 {
273 if (chr == '"' || chr == "'") 273 if (chr == '"' || chr == "'")
274 sep = chr; 274 sep = chr;
275 else if (start == null) // look for the start of an ID 275 else if (start == null) // look for the start of an ID
276 { 276 {
277 if (chr == "#") 277 if (chr == "#")
278 start = i; 278 start = i;
279 } 279 }
280 else if (chr != "-" && chr != "_" && 280 else if (chr != "-" && chr != "_" &&
281 (chr < "0" || 281 (chr < "0" ||
282 chr > "9" && chr < "A" || 282 chr > "9" && chr < "A" ||
283 chr > "Z" && chr < "a" || 283 chr > "Z" && chr < "a" ||
284 chr > "z" && chr < "\x80")) // look for the end of the ID 284 chr > "z" && chr < "\x80")) // look for the end of the ID
285 { 285 {
286 positions.push({start: start, end: i}); 286 positions.push({start: start, end: i});
287 start = null; 287 start = null;
288 } 288 }
289 } 289 }
290 } 290 }
291 if (start != null) 291 if (start != null)
292 positions.push({start: start, end: selector.length}); 292 positions.push({start: start, end: selector.length});
293 293
294 // Now replace them all with the [id="someID"] form 294 // Now replace them all with the [id="someID"] form
295 let newSelector = ""; 295 let newSelector = [];
296 let position = 0; 296 let i = 0;
297 for (let ID of positions) 297 for (let pos of positions)
298 { 298 {
299 newSelector += selector.substring(position, ID.start); 299 newSelector.push(selector.substring(i, pos.start));
300 newSelector += '[id=' + selector.substring(ID.start + 1, ID.end) + ']'; 300 newSelector.push('[id=' + selector.substring(pos.start + 1, pos.end) + ']');
301 position = ID.end; 301 i = pos.end;
302 } 302 }
303 newSelector += selector.substring(position); 303 newSelector.push(selector.substring(i));
304 304
305 return newSelector; 305 return newSelector.join("");
306 } 306 }
307 307
308 function logRules() 308 function logRules()
309 { 309 {
310 let rules = []; 310 let rules = [];
311 311
312 function addRule(rule) 312 function addRule(rule)
313 { 313 {
314 if (!hasNonASCI(rule)) 314 if (!hasNonASCI(rule))
315 rules.push(rule); 315 rules.push(rule);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 addRule(convertFilter(filter, "block", true)); 358 addRule(convertFilter(filter, "block", true));
359 for (let filter of requestExceptions) 359 for (let filter of requestExceptions)
360 addRule(convertFilter(filter, "ignore-previous-rules", true)); 360 addRule(convertFilter(filter, "ignore-previous-rules", true));
361 361
362 console.log(JSON.stringify(rules, null, "\t")); 362 console.log(JSON.stringify(rules, null, "\t"));
363 } 363 }
364 364
365 let rl = readline.createInterface({input: process.stdin, terminal: false}); 365 let rl = readline.createInterface({input: process.stdin, terminal: false});
366 rl.on("line", parseFilter); 366 rl.on("line", parseFilter);
367 rl.on("close", logRules); 367 rl.on("close", logRules);
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld