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

Side by Side Diff: lib/filterClasses.js

Issue 29790629: Issue 6690 - Always ignore trailing dot in document domain (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Ignore trailing dot in ElemHide.getSelectorsForDomain Created May 26, 2018, 12:10 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/domainRestrictions.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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 domainSource: null, 379 domainSource: null,
380 380
381 /** 381 /**
382 * Separator character used in domainSource property, must be 382 * Separator character used in domainSource property, must be
383 * overridden by subclasses 383 * overridden by subclasses
384 * @type {string} 384 * @type {string}
385 */ 385 */
386 domainSeparator: null, 386 domainSeparator: null,
387 387
388 /** 388 /**
389 * Determines whether the trailing dot in domain names isn't important and
390 * should be ignored, must be overridden by subclasses.
391 * @type {boolean}
392 */
393 ignoreTrailingDot: true,
394
395 /**
396 * Determines whether domainSource is already upper-case, 389 * Determines whether domainSource is already upper-case,
397 * can be overridden by subclasses. 390 * can be overridden by subclasses.
398 * @type {boolean} 391 * @type {boolean}
399 */ 392 */
400 domainSourceIsUpperCase: false, 393 domainSourceIsUpperCase: false,
401 394
402 /** 395 /**
403 * Map containing domains that this filter should match on/not match 396 * Map containing domains that this filter should match on/not match
404 * on or null if the filter should match on all domains 397 * on or null if the filter should match on all domains
405 * @type {?Map.<string,boolean>} 398 * @type {?Map.<string,boolean>}
(...skipping 13 matching lines...) Expand all
419 let source = this.domainSource; 412 let source = this.domainSource;
420 if (!this.domainSourceIsUpperCase) 413 if (!this.domainSourceIsUpperCase)
421 { 414 {
422 // RegExpFilter already have uppercase domains 415 // RegExpFilter already have uppercase domains
423 source = source.toUpperCase(); 416 source = source.toUpperCase();
424 } 417 }
425 let list = source.split(this.domainSeparator); 418 let list = source.split(this.domainSeparator);
426 if (list.length == 1 && list[0][0] != "~") 419 if (list.length == 1 && list[0][0] != "~")
427 { 420 {
428 // Fast track for the common one-domain scenario 421 // Fast track for the common one-domain scenario
429 if (this.ignoreTrailingDot)
430 list[0] = list[0].replace(/\.+$/, "");
431 domains = new Map([["", false], [list[0], true]]); 422 domains = new Map([["", false], [list[0], true]]);
432 } 423 }
433 else 424 else
434 { 425 {
435 let hasIncludes = false; 426 let hasIncludes = false;
436 for (let i = 0; i < list.length; i++) 427 for (let i = 0; i < list.length; i++)
437 { 428 {
438 let domain = list[i]; 429 let domain = list[i];
439 if (this.ignoreTrailingDot)
440 domain = domain.replace(/\.+$/, "");
441 if (domain == "") 430 if (domain == "")
442 continue; 431 continue;
443 432
444 let include; 433 let include;
445 if (domain[0] == "~") 434 if (domain[0] == "~")
446 { 435 {
447 include = false; 436 include = false;
448 domain = domain.substr(1); 437 domain = domain.substr(1);
449 } 438 }
450 else 439 else
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 483
495 // If no domains are set the rule matches everywhere 484 // If no domains are set the rule matches everywhere
496 if (!this.domains) 485 if (!this.domains)
497 return true; 486 return true;
498 487
499 // If the document has no host name, match only if the filter 488 // If the document has no host name, match only if the filter
500 // isn't restricted to specific domains 489 // isn't restricted to specific domains
501 if (!docDomain) 490 if (!docDomain)
502 return this.domains.get(""); 491 return this.domains.get("");
503 492
504 if (this.ignoreTrailingDot) 493 docDomain = docDomain.replace(/\.+$/, "").toUpperCase();
505 docDomain = docDomain.replace(/\.+$/, "");
506 docDomain = docDomain.toUpperCase();
507 494
508 while (true) 495 while (true)
509 { 496 {
510 let isDomainIncluded = this.domains.get(docDomain); 497 let isDomainIncluded = this.domains.get(docDomain);
511 if (typeof isDomainIncluded != "undefined") 498 if (typeof isDomainIncluded != "undefined")
512 return isDomainIncluded; 499 return isDomainIncluded;
513 500
514 let nextDot = docDomain.indexOf("."); 501 let nextDot = docDomain.indexOf(".");
515 if (nextDot < 0) 502 if (nextDot < 0)
516 break; 503 break;
517 docDomain = docDomain.substr(nextDot + 1); 504 docDomain = docDomain.substr(nextDot + 1);
518 } 505 }
519 return this.domains.get(""); 506 return this.domains.get("");
520 }, 507 },
521 508
522 /** 509 /**
523 * Checks whether this filter is active only on a domain and its subdomains. 510 * Checks whether this filter is active only on a domain and its subdomains.
524 * @param {string} docDomain 511 * @param {string} docDomain
525 * @return {boolean} 512 * @return {boolean}
526 */ 513 */
527 isActiveOnlyOnDomain(docDomain) 514 isActiveOnlyOnDomain(docDomain)
528 { 515 {
529 if (!docDomain || !this.domains || this.domains.get("")) 516 if (!docDomain || !this.domains || this.domains.get(""))
530 return false; 517 return false;
531 518
532 if (this.ignoreTrailingDot) 519 docDomain = docDomain.replace(/\.+$/, "").toUpperCase();
533 docDomain = docDomain.replace(/\.+$/, "");
534 docDomain = docDomain.toUpperCase();
535 520
536 for (let [domain, isIncluded] of this.domains) 521 for (let [domain, isIncluded] of this.domains)
537 { 522 {
538 if (isIncluded && domain != docDomain) 523 if (isIncluded && domain != docDomain)
539 { 524 {
540 if (domain.length <= docDomain.length) 525 if (domain.length <= docDomain.length)
541 return false; 526 return false;
542 527
543 if (!domain.endsWith("." + docDomain)) 528 if (!domain.endsWith("." + docDomain))
544 return false; 529 return false;
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 } 993 }
1009 exports.ElemHideBase = ElemHideBase; 994 exports.ElemHideBase = ElemHideBase;
1010 995
1011 ElemHideBase.prototype = extend(ActiveFilter, { 996 ElemHideBase.prototype = extend(ActiveFilter, {
1012 /** 997 /**
1013 * @see ActiveFilter.domainSeparator 998 * @see ActiveFilter.domainSeparator
1014 */ 999 */
1015 domainSeparator: ",", 1000 domainSeparator: ",",
1016 1001
1017 /** 1002 /**
1018 * @see ActiveFilter.ignoreTrailingDot
1019 */
1020 ignoreTrailingDot: false,
1021
1022 /**
1023 * Host names or domains the filter should be restricted to (can be null for 1003 * Host names or domains the filter should be restricted to (can be null for
1024 * no restriction) 1004 * no restriction)
1025 * @type {?string} 1005 * @type {?string}
1026 */ 1006 */
1027 selectorDomains: null, 1007 selectorDomains: null,
1028 /** 1008 /**
1029 * CSS selector for the HTML elements that should be hidden 1009 * CSS selector for the HTML elements that should be hidden
1030 * @type {string} 1010 * @type {string}
1031 */ 1011 */
1032 selector: null 1012 selector: null
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 */ 1094 */
1115 function ElemHideEmulationFilter(text, domains, selector) 1095 function ElemHideEmulationFilter(text, domains, selector)
1116 { 1096 {
1117 ElemHideBase.call(this, text, domains, selector); 1097 ElemHideBase.call(this, text, domains, selector);
1118 } 1098 }
1119 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; 1099 exports.ElemHideEmulationFilter = ElemHideEmulationFilter;
1120 1100
1121 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { 1101 ElemHideEmulationFilter.prototype = extend(ElemHideBase, {
1122 type: "elemhideemulation" 1102 type: "elemhideemulation"
1123 }); 1103 });
OLDNEW
« no previous file with comments | « lib/elemHide.js ('k') | test/domainRestrictions.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld