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 more feedback Created Feb. 17, 2016, 3:12 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
Sebastian Noack 2016/02/17 15:24:37 Nit: This code has bee ncopied from cssProperties.
kzar 2016/02/17 15:35:03 Done.
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 < "0" && chr != "-" || 280 else if (chr != "-" && chr != "_" &&
281 chr > "9" && chr < "A" || 281 (chr < "0" ||
282 chr > "Z" && chr != "_" && chr < "a" || 282 chr > "9" && chr < "A" ||
283 chr > "z" && chr < "\x80") // look for the end of the ID 283 chr > "Z" && chr < "a" ||
284 chr > "z" && chr < "\x80")) // look for the end of the ID
284 { 285 {
285 positions.push({start: start, end: i}); 286 positions.push({start: start, end: i});
286 start = null; 287 start = null;
287 } 288 }
288 } 289 }
289 } 290 }
290 if (start != null) 291 if (start != null)
291 positions.push({start: start, end: selector.length}); 292 positions.push({start: start, end: selector.length});
292 293
293 // Now replace them all with the [id="someID"] form 294 // Now replace them all with the [id="someID"] form
294 let newSelector = ""; 295 let newSelector = [];
Sebastian Noack 2016/02/17 15:24:37 Concatenating strings in a loop is expensive. You
kzar 2016/02/17 15:35:04 Done.
295 let position = 0; 296 let i = 0;
296 for (let ID of positions) 297 for (let pos of positions)
Sebastian Noack 2016/02/17 15:24:37 Nit: The variable shouldn't start with uppercase.
kzar 2016/02/17 15:35:04 Done.
297 { 298 {
298 newSelector += selector.substring(position, ID.start); 299 newSelector.push(selector.substring(i, pos.start));
299 newSelector += '[id=' + selector.substring(ID.start + 1, ID.end) + ']'; 300 newSelector.push('[id=' + selector.substring(pos.start + 1, pos.end) + ']');
300 position = ID.end; 301 i = pos.end;
301 } 302 }
302 newSelector += selector.substring(position); 303 newSelector.push(selector.substring(i));
303 304
304 return newSelector; 305 return newSelector.join("");
305 } 306 }
306 307
307 function logRules() 308 function logRules()
308 { 309 {
309 let rules = []; 310 let rules = [];
310 311
311 function addRule(rule) 312 function addRule(rule)
312 { 313 {
313 if (!hasNonASCI(rule)) 314 if (!hasNonASCI(rule))
314 rules.push(rule); 315 rules.push(rule);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 addRule(convertFilter(filter, "block", true)); 358 addRule(convertFilter(filter, "block", true));
358 for (let filter of requestExceptions) 359 for (let filter of requestExceptions)
359 addRule(convertFilter(filter, "ignore-previous-rules", true)); 360 addRule(convertFilter(filter, "ignore-previous-rules", true));
360 361
361 console.log(JSON.stringify(rules, null, "\t")); 362 console.log(JSON.stringify(rules, null, "\t"));
362 } 363 }
363 364
364 let rl = readline.createInterface({input: process.stdin, terminal: false}); 365 let rl = readline.createInterface({input: process.stdin, terminal: false});
365 rl.on("line", parseFilter); 366 rl.on("line", parseFilter);
366 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