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

Delta Between Two Patch Sets: lib/common.js

Issue 29863579: Issue 6868 - Enable capturing of surrounding wildcards for rewrite filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Add comment in test file Created Aug. 24, 2018, 4:42 p.m.
Right Patch Set: Rename to captureAll Created Sept. 1, 2018, 2:57 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 | lib/filterClasses.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 14 matching lines...) Expand all
25 function textToRegExp(text) 25 function textToRegExp(text)
26 { 26 {
27 return text.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); 27 return text.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
28 } 28 }
29 29
30 exports.textToRegExp = textToRegExp; 30 exports.textToRegExp = textToRegExp;
31 31
32 /** 32 /**
33 * Converts filter text into regular expression string 33 * Converts filter text into regular expression string
34 * @param {string} text as in Filter() 34 * @param {string} text as in Filter()
35 * @param {boolean} [optimize=true] whether to optimize the regular expression 35 * @param {boolean} [captureAll=false] whether to enable the capturing of
36 * leading and trailing wildcards in the filter text; by default, leading and
37 * trailing wildcards are stripped out
36 * @return {string} regular expression representation of filter text 38 * @return {string} regular expression representation of filter text
37 */ 39 */
38 function filterToRegExp(text, optimize = true) 40 function filterToRegExp(text, captureAll = false)
hub 2018/08/29 16:23:50 also, on second thought, I'm not certain that `opt
Manish Jethani 2018/09/01 14:57:52 OK, it already captures everything else, just not
39 { 41 {
40 if (optimize) 42 // remove multiple wildcards
41 { 43 text = text.replace(/\*+/g, "*");
42 // remove multiple wildcards 44
43 text = text.replace(/\*+/g, "*"); 45 if (!captureAll)
hub 2018/08/28 22:02:55 I think we should keep this one unconditionally li
Manish Jethani 2018/08/29 13:25:24 Since the `optimize` argument is supposed to skip
hub 2018/08/29 16:23:50 this is more about correctness IMHO. There is an e
Manish Jethani 2018/09/01 14:57:52 Alright, if we go with the renaming then it makes
44 46 {
45 // remove leading wildcard 47 // remove leading wildcard
46 if (text[0] == "*") 48 if (text[0] == "*")
47 text = text.substring(1); 49 text = text.substring(1);
48 50
49 // remove trailing wildcard 51 // remove trailing wildcard
50 if (text[text.length - 1] == "*") 52 if (text[text.length - 1] == "*")
51 text = text.substring(0, text.length - 1); 53 text = text.substring(0, text.length - 1);
52 } 54 }
53 55
54 return text 56 return text
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // Note that the first group in the regular expression is optional. If it 207 // Note that the first group in the regular expression is optional. If it
206 // doesn't match (e.g. "#foo::nth-child(1)"), type will be an empty string. 208 // doesn't match (e.g. "#foo::nth-child(1)"), type will be an empty string.
207 qualifiedSelector += sub.substr(0, index) + type + qualifier + rest; 209 qualifiedSelector += sub.substr(0, index) + type + qualifier + rest;
208 } 210 }
209 211
210 // Remove the initial comma and space. 212 // Remove the initial comma and space.
211 return qualifiedSelector.substr(2); 213 return qualifiedSelector.substr(2);
212 } 214 }
213 215
214 exports.qualifySelector = qualifySelector; 216 exports.qualifySelector = qualifySelector;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld