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

Side by Side Diff: lib/filterClasses.js

Issue 29800595: Issue 6735 - Store domains in lower case (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebase Created June 7, 2018, 10:17 a.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 | « lib/elemHide.js ('k') | test/filterClasses.js » ('j') | no next file with comments »
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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
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 let type = (option[0] == "~" ? option.substr(1) : option)
759 if (option in RegExpFilter.typeMap) 759 .replace(/-/, "_").toUpperCase();
760 option = option.toLowerCase();
761 if (type in RegExpFilter.typeMap)
760 { 762 {
761 if (contentType == null) 763 if (option[0] == "~")
762 contentType = 0; 764 {
763 contentType |= RegExpFilter.typeMap[option]; 765 if (contentType == null)
766 ({contentType} = RegExpFilter.prototype);
767 contentType &= ~RegExpFilter.typeMap[type];
768 }
769 else
770 {
771 if (contentType == null)
772 contentType = 0;
773 contentType |= RegExpFilter.typeMap[type];
764 774
765 if (option == "CSP" && value) 775 if (type == "CSP" && value)
766 csp = value; 776 csp = value;
777 }
767 } 778 }
768 else if (option[0] == "~" && option.substr(1) in RegExpFilter.typeMap) 779 else if (option == "match-case")
769 {
770 if (contentType == null)
771 ({contentType} = RegExpFilter.prototype);
772 contentType &= ~RegExpFilter.typeMap[option.substr(1)];
773 }
774 else if (option == "MATCH_CASE")
775 matchCase = true; 780 matchCase = true;
776 else if (option == "~MATCH_CASE") 781 else if (option == "~match-case")
777 matchCase = false; 782 matchCase = false;
778 else if (option == "DOMAIN" && value) 783 else if (option == "domain" && value)
779 domains = value.toUpperCase(); 784 domains = value.toLowerCase();
780 else if (option == "THIRD_PARTY") 785 else if (option == "third-party")
781 thirdParty = true; 786 thirdParty = true;
782 else if (option == "~THIRD_PARTY") 787 else if (option == "~third-party")
783 thirdParty = false; 788 thirdParty = false;
784 else if (option == "COLLAPSE") 789 else if (option == "collapse")
785 collapse = true; 790 collapse = true;
786 else if (option == "~COLLAPSE") 791 else if (option == "~collapse")
787 collapse = false; 792 collapse = false;
788 else if (option == "SITEKEY" && value) 793 else if (option == "sitekey" && value)
789 sitekeys = value.toUpperCase(); 794 sitekeys = value.toUpperCase();
790 else if (option == "REWRITE" && value) 795 else if (option == "rewrite" && value)
791 rewrite = value; 796 rewrite = value;
792 else 797 else
793 return new InvalidFilter(origText, "filter_unknown_option"); 798 return new InvalidFilter(origText, "filter_unknown_option");
794 } 799 }
795 } 800 }
796 801
797 // For security reasons, never match $rewrite filters 802 // For security reasons, never match $rewrite filters
798 // against requests that might load any code to be executed. 803 // against requests that might load any code to be executed.
799 if (rewrite != null) 804 if (rewrite != null)
800 { 805 {
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 */ 1087 */
1083 function ElemHideEmulationFilter(text, domains, selector) 1088 function ElemHideEmulationFilter(text, domains, selector)
1084 { 1089 {
1085 ElemHideBase.call(this, text, domains, selector); 1090 ElemHideBase.call(this, text, domains, selector);
1086 } 1091 }
1087 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; 1092 exports.ElemHideEmulationFilter = ElemHideEmulationFilter;
1088 1093
1089 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { 1094 ElemHideEmulationFilter.prototype = extend(ElemHideBase, {
1090 type: "elemhideemulation" 1095 type: "elemhideemulation"
1091 }); 1096 });
OLDNEW
« no previous file with comments | « lib/elemHide.js ('k') | test/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld