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

Side by Side Diff: lib/filterClasses.js

Issue 29874589: Issue 6927 - Expose pattern from RegExpFilter (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Sept. 4, 2018, 2:41 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | lib/matcher.js » ('j') | lib/matcher.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 * @type {Map.<string,Filter>} 88 * @type {Map.<string,Filter>}
89 */ 89 */
90 Filter.knownFilters = new Map(); 90 Filter.knownFilters = new Map();
91 91
92 /** 92 /**
93 * Regular expression that content filters should match 93 * Regular expression that content filters should match
94 * @type {RegExp} 94 * @type {RegExp}
95 */ 95 */
96 Filter.contentRegExp = /^([^/*|@"!]*?)#([@?$])?#(.+)$/; 96 Filter.contentRegExp = /^([^/*|@"!]*?)#([@?$])?#(.+)$/;
97 /** 97 /**
98 * Regular expression that RegExp filters specified as RegExps should match
99 * @type {RegExp}
100 */
101 Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^, \s]+)?)*)?$/;
Manish Jethani 2018/09/04 14:50:47 This appears not to be used anywhere and can be re
102 /**
103 * Regular expression that options on a RegExp filter should match 98 * Regular expression that options on a RegExp filter should match
104 * @type {RegExp} 99 * @type {RegExp}
105 */ 100 */
106 Filter.optionsRegExp = /\$(~?[\w-]+(?:=[^,]*)?(?:,~?[\w-]+(?:=[^,]*)?)*)$/; 101 Filter.optionsRegExp = /\$(~?[\w-]+(?:=[^,]*)?(?:,~?[\w-]+(?:=[^,]*)?)*)$/;
107 /** 102 /**
108 * Regular expression that matches an invalid Content Security Policy 103 * Regular expression that matches an invalid Content Security Policy
109 * @type {RegExp} 104 * @type {RegExp}
110 */ 105 */
111 Filter.invalidCSPRegExp = /(;|^) ?(base-uri|referrer|report-to|report-uri|upgrad e-insecure-requests)\b/i; 106 Filter.invalidCSPRegExp = /(;|^) ?(base-uri|referrer|report-to|report-uri|upgrad e-insecure-requests)\b/i;
112 107
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 { 601 {
607 // The filter is a regular expression - convert it immediately to 602 // The filter is a regular expression - convert it immediately to
608 // catch syntax errors 603 // catch syntax errors
609 let regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2), 604 let regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2),
610 this.matchCase ? "" : "i"); 605 this.matchCase ? "" : "i");
611 Object.defineProperty(this, "regexp", {value: regexp}); 606 Object.defineProperty(this, "regexp", {value: regexp});
612 } 607 }
613 else 608 else
614 { 609 {
615 // No need to convert this filter to regular expression yet, do it on demand 610 // No need to convert this filter to regular expression yet, do it on demand
616 this.regexpSource = regexpSource; 611 this.pattern = regexpSource;
617 } 612 }
618 } 613 }
619 exports.RegExpFilter = RegExpFilter; 614 exports.RegExpFilter = RegExpFilter;
620 615
621 RegExpFilter.prototype = extend(ActiveFilter, { 616 RegExpFilter.prototype = extend(ActiveFilter, {
622 /** 617 /**
623 * @see ActiveFilter.domainSourceIsLowerCase 618 * @see ActiveFilter.domainSourceIsLowerCase
624 */ 619 */
625 domainSourceIsLowerCase: true, 620 domainSourceIsLowerCase: true,
626 621
(...skipping 14 matching lines...) Expand all
641 }, 636 },
642 637
643 /** 638 /**
644 * @see ActiveFilter.domainSeparator 639 * @see ActiveFilter.domainSeparator
645 */ 640 */
646 domainSeparator: "|", 641 domainSeparator: "|",
647 642
648 /** 643 /**
649 * Expression from which a regular expression should be generated - 644 * Expression from which a regular expression should be generated -
650 * for delayed creation of the regexp property 645 * for delayed creation of the regexp property
651 * @type {string} 646 * @type {?string}
652 */ 647 */
653 regexpSource: null, 648 pattern: null,
654 /** 649 /**
655 * Regular expression to be used when testing against this filter 650 * Regular expression to be used when testing against this filter
656 * @type {RegExp} 651 * @type {RegExp}
657 */ 652 */
658 get regexp() 653 get regexp()
659 { 654 {
660 let source = filterToRegExp(this.regexpSource); 655 let source = filterToRegExp(this.pattern);
661 let regexp = new RegExp(source, this.matchCase ? "" : "i"); 656 let regexp = new RegExp(source, this.matchCase ? "" : "i");
662 Object.defineProperty(this, "regexp", {value: regexp}); 657 Object.defineProperty(this, "regexp", {value: regexp});
663 this.regexpSource = null;
664 return regexp; 658 return regexp;
665 }, 659 },
666 /** 660 /**
667 * Content types the filter applies to, combination of values from 661 * Content types the filter applies to, combination of values from
668 * RegExpFilter.typeMap 662 * RegExpFilter.typeMap
669 * @type {number} 663 * @type {number}
670 */ 664 */
671 contentType: 0x7FFFFFFF, 665 contentType: 0x7FFFFFFF,
672 /** 666 /**
673 * Defines whether the filter should distinguish between lower and 667 * Defines whether the filter should distinguish between lower and
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 1175
1182 /** 1176 /**
1183 * Script that should be executed 1177 * Script that should be executed
1184 * @type {string} 1178 * @type {string}
1185 */ 1179 */
1186 get script() 1180 get script()
1187 { 1181 {
1188 return this.body; 1182 return this.body;
1189 } 1183 }
1190 }); 1184 });
OLDNEW
« no previous file with comments | « no previous file | lib/matcher.js » ('j') | lib/matcher.js » ('J')

Powered by Google App Engine
This is Rietveld