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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterClasses.js
===================================================================
--- a/lib/filterClasses.js
+++ b/lib/filterClasses.js
@@ -543,17 +543,20 @@
if (!domains)
return true;
// If the document has no host name, match only if the filter
// isn't restricted to specific domains
if (!docDomain)
return domains.get("");
- docDomain = docDomain.replace(/\.+$/, "").toLowerCase();
+ if (docDomain[docDomain.length - 1] == ".")
+ docDomain = docDomain.replace(/\.+$/, "");
+
+ docDomain = docDomain.toLowerCase();
while (true)
{
let isDomainIncluded = domains.get(docDomain);
if (typeof isDomainIncluded != "undefined")
return isDomainIncluded;
let nextDot = docDomain.indexOf(".");
@@ -571,17 +574,20 @@
*/
isActiveOnlyOnDomain(docDomain)
{
let {domains} = this;
if (!docDomain || !domains || domains.get(""))
return false;
- docDomain = docDomain.replace(/\.+$/, "").toLowerCase();
+ if (docDomain[docDomain.length - 1] == ".")
+ docDomain = docDomain.replace(/\.+$/, "");
+
+ docDomain = docDomain.toLowerCase();
for (let [domain, isIncluded] of domains)
{
if (isIncluded && domain != docDomain)
{
if (domain.length <= docDomain.length)
return false;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld