| OLD | NEW |
| 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 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 * @param {boolean} [matchCase] | 681 * @param {boolean} [matchCase] |
| 682 * Defines whether the filter should distinguish between lower and upper case | 682 * Defines whether the filter should distinguish between lower and upper case |
| 683 * letters | 683 * letters |
| 684 * @param {string} [domains] | 684 * @param {string} [domains] |
| 685 * Domains that the filter is restricted to, e.g. "foo.com|bar.com|~baz.com" | 685 * Domains that the filter is restricted to, e.g. "foo.com|bar.com|~baz.com" |
| 686 * @param {boolean} [thirdParty] | 686 * @param {boolean} [thirdParty] |
| 687 * Defines whether the filter should apply to third-party or first-party | 687 * Defines whether the filter should apply to third-party or first-party |
| 688 * content only | 688 * content only |
| 689 * @param {string} [sitekeys] | 689 * @param {string} [sitekeys] |
| 690 * Public keys of websites that this filter should apply to | 690 * Public keys of websites that this filter should apply to |
| 691 * @param {?string} [rewrite] |
| 692 * The (optional) rule specifying how to rewrite the URL. See |
| 693 * BlockingFilter.prototype.rewrite. |
| 691 * @constructor | 694 * @constructor |
| 692 * @augments ActiveFilter | 695 * @augments ActiveFilter |
| 693 */ | 696 */ |
| 694 function RegExpFilter(text, regexpSource, contentType, matchCase, domains, | 697 function RegExpFilter(text, regexpSource, contentType, matchCase, domains, |
| 695 thirdParty, sitekeys) | 698 thirdParty, sitekeys, rewrite) |
| 696 { | 699 { |
| 697 ActiveFilter.call(this, text, domains); | 700 ActiveFilter.call(this, text, domains); |
| 698 | 701 |
| 699 if (contentType != null) | 702 if (contentType != null) |
| 700 this.contentType = contentType; | 703 this.contentType = contentType; |
| 701 if (matchCase) | 704 if (matchCase) |
| 702 this.matchCase = matchCase; | 705 this.matchCase = matchCase; |
| 703 if (thirdParty != null) | 706 if (thirdParty != null) |
| 704 this.thirdParty = thirdParty; | 707 this.thirdParty = thirdParty; |
| 705 if (sitekeys != null) | 708 if (sitekeys != null) |
| 706 this.sitekeySource = sitekeys; | 709 this.sitekeySource = sitekeys; |
| 707 | 710 |
| 708 if (regexpSource.length >= 2 && | 711 if (regexpSource.length >= 2 && |
| 709 regexpSource[0] == "/" && | 712 regexpSource[0] == "/" && |
| 710 regexpSource[regexpSource.length - 1] == "/") | 713 regexpSource[regexpSource.length - 1] == "/") |
| 711 { | 714 { |
| 712 // The filter is a regular expression - convert it immediately to | 715 // The filter is a regular expression - convert it immediately to |
| 713 // catch syntax errors | 716 // catch syntax errors |
| 714 let regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2), | 717 let regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2), |
| 715 this.matchCase ? "" : "i"); | 718 this.matchCase ? "" : "i"); |
| 716 Object.defineProperty(this, "regexp", {value: regexp}); | 719 Object.defineProperty(this, "regexp", {value: regexp}); |
| 717 } | 720 } |
| 718 else | 721 else |
| 719 { | 722 { |
| 723 // Patterns like /foo/bar/* exist so that they are not treated as regular |
| 724 // expressions. We drop any superflous wildcards here so our optimizations |
| 725 // can kick in. |
| 726 if (rewrite == null) |
| 727 regexpSource = regexpSource.replace(/^\*+/, "").replace(/\*+$/, ""); |
| 728 |
| 720 if (!this.matchCase && isLiteralPattern(regexpSource)) | 729 if (!this.matchCase && isLiteralPattern(regexpSource)) |
| 721 regexpSource = regexpSource.toLowerCase(); | 730 regexpSource = regexpSource.toLowerCase(); |
| 722 | 731 |
| 723 // No need to convert this filter to regular expression yet, do it on demand | 732 // No need to convert this filter to regular expression yet, do it on demand |
| 724 this.pattern = regexpSource; | 733 this.pattern = regexpSource; |
| 725 } | 734 } |
| 726 } | 735 } |
| 727 exports.RegExpFilter = RegExpFilter; | 736 exports.RegExpFilter = RegExpFilter; |
| 728 | 737 |
| 729 RegExpFilter.prototype = extend(ActiveFilter, { | 738 RegExpFilter.prototype = extend(ActiveFilter, { |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 * @param {?string} [rewrite] | 1072 * @param {?string} [rewrite] |
| 1064 * The (optional) rule specifying how to rewrite the URL. See | 1073 * The (optional) rule specifying how to rewrite the URL. See |
| 1065 * BlockingFilter.prototype.rewrite. | 1074 * BlockingFilter.prototype.rewrite. |
| 1066 * @constructor | 1075 * @constructor |
| 1067 * @augments RegExpFilter | 1076 * @augments RegExpFilter |
| 1068 */ | 1077 */ |
| 1069 function BlockingFilter(text, regexpSource, contentType, matchCase, domains, | 1078 function BlockingFilter(text, regexpSource, contentType, matchCase, domains, |
| 1070 thirdParty, sitekeys, collapse, csp, rewrite) | 1079 thirdParty, sitekeys, collapse, csp, rewrite) |
| 1071 { | 1080 { |
| 1072 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, | 1081 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, |
| 1073 thirdParty, sitekeys); | 1082 thirdParty, sitekeys, rewrite); |
| 1074 | 1083 |
| 1075 if (collapse != null) | 1084 if (collapse != null) |
| 1076 this.collapse = collapse; | 1085 this.collapse = collapse; |
| 1077 | 1086 |
| 1078 if (csp != null) | 1087 if (csp != null) |
| 1079 this.csp = csp; | 1088 this.csp = csp; |
| 1080 | 1089 |
| 1081 if (rewrite != null) | 1090 if (rewrite != null) |
| 1082 this.rewrite = rewrite; | 1091 this.rewrite = rewrite; |
| 1083 } | 1092 } |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 | 1362 |
| 1354 /** | 1363 /** |
| 1355 * Script that should be executed | 1364 * Script that should be executed |
| 1356 * @type {string} | 1365 * @type {string} |
| 1357 */ | 1366 */ |
| 1358 get script() | 1367 get script() |
| 1359 { | 1368 { |
| 1360 return this.body; | 1369 return this.body; |
| 1361 } | 1370 } |
| 1362 }); | 1371 }); |
| OLD | NEW |