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

Side by Side Diff: lib/filterClasses.js

Issue 29892593: Noissue - Avoid string replacement for domains with no trailing dots (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Sept. 26, 2018, 10:55 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 | no next file » | 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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 541
542 // If no domains are set the rule matches everywhere 542 // If no domains are set the rule matches everywhere
543 if (!domains) 543 if (!domains)
544 return true; 544 return true;
545 545
546 // If the document has no host name, match only if the filter 546 // If the document has no host name, match only if the filter
547 // isn't restricted to specific domains 547 // isn't restricted to specific domains
548 if (!docDomain) 548 if (!docDomain)
549 return domains.get(""); 549 return domains.get("");
550 550
551 docDomain = docDomain.replace(/\.+$/, "").toLowerCase(); 551 if (docDomain[docDomain.length - 1] == ".")
552 docDomain = docDomain.replace(/\.+$/, "");
553
554 docDomain = docDomain.toLowerCase();
552 555
553 while (true) 556 while (true)
554 { 557 {
555 let isDomainIncluded = domains.get(docDomain); 558 let isDomainIncluded = domains.get(docDomain);
556 if (typeof isDomainIncluded != "undefined") 559 if (typeof isDomainIncluded != "undefined")
557 return isDomainIncluded; 560 return isDomainIncluded;
558 561
559 let nextDot = docDomain.indexOf("."); 562 let nextDot = docDomain.indexOf(".");
560 if (nextDot < 0) 563 if (nextDot < 0)
561 break; 564 break;
562 docDomain = docDomain.substr(nextDot + 1); 565 docDomain = docDomain.substr(nextDot + 1);
563 } 566 }
564 return domains.get(""); 567 return domains.get("");
565 }, 568 },
566 569
567 /** 570 /**
568 * Checks whether this filter is active only on a domain and its subdomains. 571 * Checks whether this filter is active only on a domain and its subdomains.
569 * @param {string} docDomain 572 * @param {string} docDomain
570 * @return {boolean} 573 * @return {boolean}
571 */ 574 */
572 isActiveOnlyOnDomain(docDomain) 575 isActiveOnlyOnDomain(docDomain)
573 { 576 {
574 let {domains} = this; 577 let {domains} = this;
575 578
576 if (!docDomain || !domains || domains.get("")) 579 if (!docDomain || !domains || domains.get(""))
577 return false; 580 return false;
578 581
579 docDomain = docDomain.replace(/\.+$/, "").toLowerCase(); 582 if (docDomain[docDomain.length - 1] == ".")
583 docDomain = docDomain.replace(/\.+$/, "");
584
585 docDomain = docDomain.toLowerCase();
580 586
581 for (let [domain, isIncluded] of domains) 587 for (let [domain, isIncluded] of domains)
582 { 588 {
583 if (isIncluded && domain != docDomain) 589 if (isIncluded && domain != docDomain)
584 { 590 {
585 if (domain.length <= docDomain.length) 591 if (domain.length <= docDomain.length)
586 return false; 592 return false;
587 593
588 if (!domain.endsWith("." + docDomain)) 594 if (!domain.endsWith("." + docDomain))
589 return false; 595 return false;
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 1237
1232 /** 1238 /**
1233 * Script that should be executed 1239 * Script that should be executed
1234 * @type {string} 1240 * @type {string}
1235 */ 1241 */
1236 get script() 1242 get script()
1237 { 1243 {
1238 return this.body; 1244 return this.body;
1239 } 1245 }
1240 }); 1246 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld