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

Delta Between Two Patch Sets: lib/filterClasses.js

Issue 29912636: Issue 7052 - Use string-based matching for literal patterns (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Add comments Created Oct. 17, 2018, 8:58 a.m.
Right Patch Set: Move code back to lib/filterClasses.js Created Oct. 21, 2018, 11:46 a.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 | test/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 12 matching lines...) Expand all
23 23
24 const {filterNotifier} = require("./filterNotifier"); 24 const {filterNotifier} = require("./filterNotifier");
25 const {extend} = require("./coreUtils"); 25 const {extend} = require("./coreUtils");
26 const {filterToRegExp} = require("./common"); 26 const {filterToRegExp} = require("./common");
27 27
28 /** 28 /**
29 * Regular expression used to match the <code>||</code> prefix in an otherwise 29 * Regular expression used to match the <code>||</code> prefix in an otherwise
30 * literal pattern. 30 * literal pattern.
31 * @type {RegExp} 31 * @type {RegExp}
32 */ 32 */
33 let tripleAnchorRegExp = new RegExp(filterToRegExp("|||")); 33 let doubleAnchorRegExp = new RegExp(filterToRegExp("||") + "$");
34 34
35 /** 35 /**
36 * All known unique domain sources mapped to their parsed values. 36 * All known unique domain sources mapped to their parsed values.
37 * @type {Map.<string,Map.<string,boolean>>} 37 * @type {Map.<string,Map.<string,boolean>>}
38 */ 38 */
39 let knownDomainMaps = new Map(); 39 let knownDomainMaps = new Map();
40 40
41 /** 41 /**
42 * Checks whether the given pattern is a string of literal characters with no 42 * Checks whether the given pattern is a string of literal characters with no
43 * wildcards or any other special characters. If the pattern is prefixed with a 43 * wildcards or any other special characters. If the pattern is prefixed with a
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 regexpSource[regexpSource.length - 1] == "/") 706 regexpSource[regexpSource.length - 1] == "/")
707 { 707 {
708 // The filter is a regular expression - convert it immediately to 708 // The filter is a regular expression - convert it immediately to
709 // catch syntax errors 709 // catch syntax errors
710 let regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2), 710 let regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2),
711 this.matchCase ? "" : "i"); 711 this.matchCase ? "" : "i");
712 Object.defineProperty(this, "regexp", {value: regexp}); 712 Object.defineProperty(this, "regexp", {value: regexp});
713 } 713 }
714 else 714 else
715 { 715 {
716 if (!this.matchCase && isLiteralPattern(regexpSource)) 716 if (!this.matchCase && isLiteralPattern(regexpSource))
Manish Jethani 2018/10/17 09:05:04 Lowercase the pattern once here if it is literal a
717 regexpSource = regexpSource.toLowerCase(); 717 regexpSource = regexpSource.toLowerCase();
718 718
719 // No need to convert this filter to regular expression yet, do it on demand 719 // No need to convert this filter to regular expression yet, do it on demand
720 this.pattern = regexpSource; 720 this.pattern = regexpSource;
721 } 721 }
722 } 722 }
723 exports.RegExpFilter = RegExpFilter; 723 exports.RegExpFilter = RegExpFilter;
724 724
725 RegExpFilter.prototype = extend(ActiveFilter, { 725 RegExpFilter.prototype = extend(ActiveFilter, {
726 /** 726 /**
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 if (!this.matchCase) 836 if (!this.matchCase)
837 location = location.toLowerCase(); 837 location = location.toLowerCase();
838 838
839 let {pattern} = this; 839 let {pattern} = this;
840 840
841 if (pattern[0] == "|" && pattern[1] == "|") 841 if (pattern[0] == "|" && pattern[1] == "|")
842 { 842 {
843 let index = location.indexOf(pattern.substring(2)); 843 let index = location.indexOf(pattern.substring(2));
844 844
845 // The "||" prefix requires that the text that follows does not start 845 // The "||" prefix requires that the text that follows does not start
846 // with a forward slash. Normally this is part of the generated regular 846 // with a forward slash.
847 // expression, but since we're faking it here with string-based matching
848 // we need to do the check ourselves.
849 return index != -1 && location[index] != "/" && 847 return index != -1 && location[index] != "/" &&
Manish Jethani 2018/10/17 09:05:04 If the index is not -1 then it's highly unlikely t
850 tripleAnchorRegExp.test(location.substring(0, index)); 848 doubleAnchorRegExp.test(location.substring(0, index));
851 } 849 }
852 850
853 return location.includes(pattern); 851 return location.includes(pattern);
854 } 852 }
855 }); 853 });
856 854
857 /** 855 /**
858 * Yields the filter itself (required to optimize {@link Matcher}). 856 * Yields the filter itself (required to optimize {@link Matcher}).
859 * @yields {RegExpFilter} 857 * @yields {RegExpFilter}
860 */ 858 */
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 1336
1339 /** 1337 /**
1340 * Script that should be executed 1338 * Script that should be executed
1341 * @type {string} 1339 * @type {string}
1342 */ 1340 */
1343 get script() 1341 get script()
1344 { 1342 {
1345 return this.body; 1343 return this.body;
1346 } 1344 }
1347 }); 1345 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld