Left: | ||
Right: |
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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
380 domainSource: null, | 380 domainSource: null, |
381 | 381 |
382 /** | 382 /** |
383 * Separator character used in domainSource property, must be | 383 * Separator character used in domainSource property, must be |
384 * overridden by subclasses | 384 * overridden by subclasses |
385 * @type {string} | 385 * @type {string} |
386 */ | 386 */ |
387 domainSeparator: null, | 387 domainSeparator: null, |
388 | 388 |
389 /** | 389 /** |
390 * Determines whether domainSource is already upper-case, | 390 * Determines whether domainSource is already lower-case, |
391 * can be overridden by subclasses. | 391 * can be overridden by subclasses. |
392 * @type {boolean} | 392 * @type {boolean} |
393 */ | 393 */ |
394 domainSourceIsUpperCase: false, | 394 domainSourceIsLowerCase: false, |
395 | 395 |
396 /** | 396 /** |
397 * Map containing domains that this filter should match on/not match | 397 * Map containing domains that this filter should match on/not match |
398 * on or null if the filter should match on all domains | 398 * on or null if the filter should match on all domains |
399 * @type {?Map.<string,boolean>} | 399 * @type {?Map.<string,boolean>} |
400 */ | 400 */ |
401 get domains() | 401 get domains() |
402 { | 402 { |
403 let domains = null; | 403 let domains = null; |
404 | 404 |
405 if (this.domainSource) | 405 if (this.domainSource) |
406 { | 406 { |
407 let source = this.domainSource; | 407 let source = this.domainSource; |
408 if (!this.domainSourceIsUpperCase) | 408 if (!this.domainSourceIsLowerCase) |
409 { | 409 { |
410 // RegExpFilter already have uppercase domains | 410 // RegExpFilter already have lowercase domains |
411 source = source.toUpperCase(); | 411 source = source.toLowerCase(); |
412 } | 412 } |
413 let list = source.split(this.domainSeparator); | 413 let list = source.split(this.domainSeparator); |
414 if (list.length == 1 && list[0][0] != "~") | 414 if (list.length == 1 && list[0][0] != "~") |
415 { | 415 { |
416 // Fast track for the common one-domain scenario | 416 // Fast track for the common one-domain scenario |
417 domains = new Map([["", false], [list[0], true]]); | 417 domains = new Map([["", false], [list[0], true]]); |
418 } | 418 } |
419 else | 419 else |
420 { | 420 { |
421 let hasIncludes = false; | 421 let hasIncludes = false; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 | 478 |
479 // If no domains are set the rule matches everywhere | 479 // If no domains are set the rule matches everywhere |
480 if (!this.domains) | 480 if (!this.domains) |
481 return true; | 481 return true; |
482 | 482 |
483 // If the document has no host name, match only if the filter | 483 // If the document has no host name, match only if the filter |
484 // isn't restricted to specific domains | 484 // isn't restricted to specific domains |
485 if (!docDomain) | 485 if (!docDomain) |
486 return this.domains.get(""); | 486 return this.domains.get(""); |
487 | 487 |
488 docDomain = docDomain.replace(/\.+$/, "").toUpperCase(); | 488 docDomain = docDomain.replace(/\.+$/, "").toLowerCase(); |
489 | 489 |
490 while (true) | 490 while (true) |
491 { | 491 { |
492 let isDomainIncluded = this.domains.get(docDomain); | 492 let isDomainIncluded = this.domains.get(docDomain); |
493 if (typeof isDomainIncluded != "undefined") | 493 if (typeof isDomainIncluded != "undefined") |
494 return isDomainIncluded; | 494 return isDomainIncluded; |
495 | 495 |
496 let nextDot = docDomain.indexOf("."); | 496 let nextDot = docDomain.indexOf("."); |
497 if (nextDot < 0) | 497 if (nextDot < 0) |
498 break; | 498 break; |
499 docDomain = docDomain.substr(nextDot + 1); | 499 docDomain = docDomain.substr(nextDot + 1); |
500 } | 500 } |
501 return this.domains.get(""); | 501 return this.domains.get(""); |
502 }, | 502 }, |
503 | 503 |
504 /** | 504 /** |
505 * Checks whether this filter is active only on a domain and its subdomains. | 505 * Checks whether this filter is active only on a domain and its subdomains. |
506 * @param {string} docDomain | 506 * @param {string} docDomain |
507 * @return {boolean} | 507 * @return {boolean} |
508 */ | 508 */ |
509 isActiveOnlyOnDomain(docDomain) | 509 isActiveOnlyOnDomain(docDomain) |
510 { | 510 { |
511 if (!docDomain || !this.domains || this.domains.get("")) | 511 if (!docDomain || !this.domains || this.domains.get("")) |
512 return false; | 512 return false; |
513 | 513 |
514 docDomain = docDomain.replace(/\.+$/, "").toUpperCase(); | 514 docDomain = docDomain.replace(/\.+$/, "").toLowerCase(); |
515 | 515 |
516 for (let [domain, isIncluded] of this.domains) | 516 for (let [domain, isIncluded] of this.domains) |
517 { | 517 { |
518 if (isIncluded && domain != docDomain) | 518 if (isIncluded && domain != docDomain) |
519 { | 519 { |
520 if (domain.length <= docDomain.length) | 520 if (domain.length <= docDomain.length) |
521 return false; | 521 return false; |
522 | 522 |
523 if (!domain.endsWith("." + docDomain)) | 523 if (!domain.endsWith("." + docDomain)) |
524 return false; | 524 return false; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
605 else | 605 else |
606 { | 606 { |
607 // No need to convert this filter to regular expression yet, do it on demand | 607 // No need to convert this filter to regular expression yet, do it on demand |
608 this.regexpSource = regexpSource; | 608 this.regexpSource = regexpSource; |
609 } | 609 } |
610 } | 610 } |
611 exports.RegExpFilter = RegExpFilter; | 611 exports.RegExpFilter = RegExpFilter; |
612 | 612 |
613 RegExpFilter.prototype = extend(ActiveFilter, { | 613 RegExpFilter.prototype = extend(ActiveFilter, { |
614 /** | 614 /** |
615 * @see ActiveFilter.domainSourceIsUpperCase | 615 * @see ActiveFilter.domainSourceIsLowerCase |
616 */ | 616 */ |
617 domainSourceIsUpperCase: true, | 617 domainSourceIsLowerCase: true, |
618 | 618 |
619 /** | 619 /** |
620 * Number of filters contained, will always be 1 (required to | 620 * Number of filters contained, will always be 1 (required to |
621 * optimize Matcher). | 621 * optimize Matcher). |
622 * @type {number} | 622 * @type {number} |
623 */ | 623 */ |
624 length: 1, | 624 length: 1, |
625 | 625 |
626 /** | 626 /** |
627 * @see ActiveFilter.domainSeparator | 627 * @see ActiveFilter.domainSeparator |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
748 text = match.input.substr(0, match.index); | 748 text = match.input.substr(0, match.index); |
749 for (let option of options) | 749 for (let option of options) |
750 { | 750 { |
751 let value = null; | 751 let value = null; |
752 let separatorIndex = option.indexOf("="); | 752 let separatorIndex = option.indexOf("="); |
753 if (separatorIndex >= 0) | 753 if (separatorIndex >= 0) |
754 { | 754 { |
755 value = option.substr(separatorIndex + 1); | 755 value = option.substr(separatorIndex + 1); |
756 option = option.substr(0, separatorIndex); | 756 option = option.substr(0, separatorIndex); |
757 } | 757 } |
758 option = option.replace(/-/, "_").toUpperCase(); | 758 |
759 if (option in RegExpFilter.typeMap) | 759 let inverse = option[0] == "~"; |
Manish Jethani
2018/06/08 05:00:41
I'm just calling it "inverse" because "option" is
kzar
2018/06/08 09:30:32
Acknowledged.
| |
760 if (inverse) | |
761 option = option.substr(1); | |
762 | |
763 let type = RegExpFilter.typeMap[option.replace(/-/, "_").toUpperCase()]; | |
Manish Jethani
2018/06/08 05:00:41
Lookup happens only once in the RegExpFilter.typeM
kzar
2018/06/08 09:30:32
Nice.
| |
764 if (type) | |
760 { | 765 { |
761 contentType |= RegExpFilter.typeMap[option]; | 766 if (inverse) |
767 { | |
768 if (contentType == null) | |
769 ({contentType} = RegExpFilter.prototype); | |
770 contentType &= ~type; | |
771 } | |
772 else | |
773 { | |
774 contentType |= type; | |
762 | 775 |
763 if (option == "CSP" && value) | 776 if (type == RegExpFilter.typeMap.CSP && value) |
Manish Jethani
2018/06/08 05:00:41
Integer comparison.
| |
764 csp = value; | 777 csp = value; |
778 } | |
765 } | 779 } |
766 else if (option[0] == "~" && option.substr(1) in RegExpFilter.typeMap) | 780 else |
767 { | 781 { |
768 if (contentType == null) | 782 switch (option.toLowerCase()) |
Manish Jethani
2018/06/08 05:00:41
Only lowercase if we get this far.
switch is clea
| |
769 ({contentType} = RegExpFilter.prototype); | 783 { |
770 contentType &= ~RegExpFilter.typeMap[option.substr(1)]; | 784 case "match-case": |
785 matchCase = !inverse; | |
Manish Jethani
2018/06/08 05:00:41
!inverse
kzar
2018/06/08 09:30:31
(Heh, it does make you wonder if storing !inverse
| |
786 break; | |
787 case "domain": | |
788 if (value) | |
Manish Jethani
2018/06/08 05:00:41
Note: This has a good side effect. Previously foo$
kzar
2018/06/08 09:30:32
Seems reasonable to me, but I wonder if this was i
sergei
2018/06/08 13:28:11
Formally, if the option is present and there are n
Manish Jethani
2018/06/08 14:12:39
For known options that must have a value but none
| |
789 domains = value.toLowerCase(); | |
790 break; | |
791 case "third-party": | |
792 thirdParty = !inverse; | |
793 break; | |
794 case "collapse": | |
795 collapse = !inverse; | |
796 break; | |
797 case "sitekey": | |
798 if (value) | |
799 sitekeys = value.toUpperCase(); | |
800 break; | |
801 case "rewrite": | |
802 if (value) | |
Manish Jethani
2018/06/08 05:00:41
Note that this also simplifies how we can accept t
kzar
2018/06/08 09:30:31
Acknowledged.
| |
803 rewrite = value; | |
804 break; | |
805 default: | |
806 return new InvalidFilter(origText, "filter_unknown_option"); | |
807 } | |
771 } | 808 } |
772 else if (option == "MATCH_CASE") | |
773 matchCase = true; | |
774 else if (option == "~MATCH_CASE") | |
775 matchCase = false; | |
776 else if (option == "DOMAIN" && value) | |
777 domains = value.toUpperCase(); | |
778 else if (option == "THIRD_PARTY") | |
779 thirdParty = true; | |
780 else if (option == "~THIRD_PARTY") | |
781 thirdParty = false; | |
782 else if (option == "COLLAPSE") | |
783 collapse = true; | |
784 else if (option == "~COLLAPSE") | |
785 collapse = false; | |
786 else if (option == "SITEKEY" && value) | |
787 sitekeys = value.toUpperCase(); | |
788 else if (option == "REWRITE" && value) | |
789 rewrite = value; | |
790 else | |
791 return new InvalidFilter(origText, "filter_unknown_option"); | |
792 } | 809 } |
793 } | 810 } |
794 | 811 |
795 // For security reasons, never match $rewrite filters | 812 // For security reasons, never match $rewrite filters |
796 // against requests that might load any code to be executed. | 813 // against requests that might load any code to be executed. |
797 if (rewrite != null) | 814 if (rewrite != null) |
798 { | 815 { |
799 if (contentType == null) | 816 if (contentType == null) |
800 ({contentType} = RegExpFilter.prototype); | 817 ({contentType} = RegExpFilter.prototype); |
801 contentType &= ~(RegExpFilter.typeMap.SCRIPT | | 818 contentType &= ~(RegExpFilter.typeMap.SCRIPT | |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1080 */ | 1097 */ |
1081 function ElemHideEmulationFilter(text, domains, selector) | 1098 function ElemHideEmulationFilter(text, domains, selector) |
1082 { | 1099 { |
1083 ElemHideBase.call(this, text, domains, selector); | 1100 ElemHideBase.call(this, text, domains, selector); |
1084 } | 1101 } |
1085 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; | 1102 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; |
1086 | 1103 |
1087 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { | 1104 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { |
1088 type: "elemhideemulation" | 1105 type: "elemhideemulation" |
1089 }); | 1106 }); |
OLD | NEW |