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

Side by Side Diff: lib/filterClasses.js

Issue 29807560: Issue 6745 - Prefer strict equality operator (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created June 14, 2018, 4:11 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 | « lib/events.js ('k') | lib/filterListener.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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 let expression = propsMatch[2]; 129 let expression = propsMatch[2];
130 let suffix = match[3].substr(propsMatch.index + propsMatch[0].length); 130 let suffix = match[3].substr(propsMatch.index + propsMatch[0].length);
131 return Filter.fromText(`${match[1]}#?#` + 131 return Filter.fromText(`${match[1]}#?#` +
132 `${prefix}:-abp-properties(${expression})${suffix}`); 132 `${prefix}:-abp-properties(${expression})${suffix}`);
133 } 133 }
134 134
135 filter = ElemHideBase.fromText( 135 filter = ElemHideBase.fromText(
136 text, match[1], match[2], match[3] 136 text, match[1], match[2], match[3]
137 ); 137 );
138 } 138 }
139 else if (text[0] == "!") 139 else if (text[0] === "!")
140 filter = new CommentFilter(text); 140 filter = new CommentFilter(text);
141 else 141 else
142 filter = RegExpFilter.fromText(text); 142 filter = RegExpFilter.fromText(text);
143 143
144 Filter.knownFilters.set(filter.text, filter); 144 Filter.knownFilters.set(filter.text, filter);
145 return filter; 145 return filter;
146 }; 146 };
147 147
148 /** 148 /**
149 * Deserializes a filter 149 * Deserializes a filter
150 * 150 *
151 * @param {Object} obj map of serialized properties and their values 151 * @param {Object} obj map of serialized properties and their values
152 * @return {Filter} filter or null if the filter couldn't be created 152 * @return {Filter} filter or null if the filter couldn't be created
153 */ 153 */
154 Filter.fromObject = function(obj) 154 Filter.fromObject = function(obj)
155 { 155 {
156 let filter = Filter.fromText(obj.text); 156 let filter = Filter.fromText(obj.text);
157 if (filter instanceof ActiveFilter) 157 if (filter instanceof ActiveFilter)
158 { 158 {
159 if ("disabled" in obj) 159 if ("disabled" in obj)
160 filter._disabled = (obj.disabled == "true"); 160 filter._disabled = (obj.disabled === "true");
161 if ("hitCount" in obj) 161 if ("hitCount" in obj)
162 filter._hitCount = parseInt(obj.hitCount, 10) || 0; 162 filter._hitCount = parseInt(obj.hitCount, 10) || 0;
163 if ("lastHit" in obj) 163 if ("lastHit" in obj)
164 filter._lastHit = parseInt(obj.lastHit, 10) || 0; 164 filter._lastHit = parseInt(obj.lastHit, 10) || 0;
165 } 165 }
166 return filter; 166 return filter;
167 }; 167 };
168 168
169 /** 169 /**
170 * Removes unnecessary whitespaces from filter text, will only return null if 170 * Removes unnecessary whitespaces from filter text, will only return null if
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // For $csp filters we must first separate out the options part of the 205 // For $csp filters we must first separate out the options part of the
206 // text, being careful to preserve its spaces. 206 // text, being careful to preserve its spaces.
207 let beforeOptions = strippedText.substring(0, optionsMatch.index); 207 let beforeOptions = strippedText.substring(0, optionsMatch.index);
208 let strippedDollarIndex = -1; 208 let strippedDollarIndex = -1;
209 let dollarIndex = -1; 209 let dollarIndex = -1;
210 do 210 do
211 { 211 {
212 strippedDollarIndex = beforeOptions.indexOf("$", strippedDollarIndex + 1); 212 strippedDollarIndex = beforeOptions.indexOf("$", strippedDollarIndex + 1);
213 dollarIndex = text.indexOf("$", dollarIndex + 1); 213 dollarIndex = text.indexOf("$", dollarIndex + 1);
214 } 214 }
215 while (strippedDollarIndex != -1); 215 while (strippedDollarIndex !== -1);
216 let optionsText = text.substr(dollarIndex + 1); 216 let optionsText = text.substr(dollarIndex + 1);
217 217
218 // Then we can normalize spaces in the options part safely 218 // Then we can normalize spaces in the options part safely
219 let options = optionsText.split(","); 219 let options = optionsText.split(",");
220 for (let i = 0; i < options.length; i++) 220 for (let i = 0; i < options.length; i++)
221 { 221 {
222 let option = options[i]; 222 let option = options[i];
223 let cspMatch = /^ *c *s *p *=/i.exec(option); 223 let cspMatch = /^ *c *s *p *=/i.exec(option);
224 if (cspMatch) 224 if (cspMatch)
225 { 225 {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 /** 318 /**
319 * Defines whether the filter is disabled 319 * Defines whether the filter is disabled
320 * @type {boolean} 320 * @type {boolean}
321 */ 321 */
322 get disabled() 322 get disabled()
323 { 323 {
324 return this._disabled; 324 return this._disabled;
325 }, 325 },
326 set disabled(value) 326 set disabled(value)
327 { 327 {
328 if (value != this._disabled) 328 if (value !== this._disabled)
329 { 329 {
330 let oldValue = this._disabled; 330 let oldValue = this._disabled;
331 this._disabled = value; 331 this._disabled = value;
332 FilterNotifier.triggerListeners("filter.disabled", this, value, oldValue); 332 FilterNotifier.triggerListeners("filter.disabled", this, value, oldValue);
333 } 333 }
334 return this._disabled; 334 return this._disabled;
335 }, 335 },
336 336
337 /** 337 /**
338 * Number of hits on the filter since the last reset 338 * Number of hits on the filter since the last reset
339 * @type {number} 339 * @type {number}
340 */ 340 */
341 get hitCount() 341 get hitCount()
342 { 342 {
343 return this._hitCount; 343 return this._hitCount;
344 }, 344 },
345 set hitCount(value) 345 set hitCount(value)
346 { 346 {
347 if (value != this._hitCount) 347 if (value !== this._hitCount)
348 { 348 {
349 let oldValue = this._hitCount; 349 let oldValue = this._hitCount;
350 this._hitCount = value; 350 this._hitCount = value;
351 FilterNotifier.triggerListeners("filter.hitCount", this, value, oldValue); 351 FilterNotifier.triggerListeners("filter.hitCount", this, value, oldValue);
352 } 352 }
353 return this._hitCount; 353 return this._hitCount;
354 }, 354 },
355 355
356 /** 356 /**
357 * Last time the filter had a hit (in milliseconds since the beginning of the 357 * Last time the filter had a hit (in milliseconds since the beginning of the
358 * epoch) 358 * epoch)
359 * @type {number} 359 * @type {number}
360 */ 360 */
361 get lastHit() 361 get lastHit()
362 { 362 {
363 return this._lastHit; 363 return this._lastHit;
364 }, 364 },
365 set lastHit(value) 365 set lastHit(value)
366 { 366 {
367 if (value != this._lastHit) 367 if (value !== this._lastHit)
368 { 368 {
369 let oldValue = this._lastHit; 369 let oldValue = this._lastHit;
370 this._lastHit = value; 370 this._lastHit = value;
371 FilterNotifier.triggerListeners("filter.lastHit", this, value, oldValue); 371 FilterNotifier.triggerListeners("filter.lastHit", this, value, oldValue);
372 } 372 }
373 return this._lastHit; 373 return this._lastHit;
374 }, 374 },
375 375
376 /** 376 /**
377 * String that the domains property should be generated from 377 * String that the domains property should be generated from
(...skipping 26 matching lines...) Expand all
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.domainSourceIsUpperCase)
409 { 409 {
410 // RegExpFilter already have uppercase domains 410 // RegExpFilter already have uppercase domains
411 source = source.toUpperCase(); 411 source = source.toUpperCase();
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;
422 for (let i = 0; i < list.length; i++) 422 for (let i = 0; i < list.length; i++)
423 { 423 {
424 let domain = list[i]; 424 let domain = list[i];
425 if (domain == "") 425 if (domain === "")
426 continue; 426 continue;
427 427
428 let include; 428 let include;
429 if (domain[0] == "~") 429 if (domain[0] === "~")
430 { 430 {
431 include = false; 431 include = false;
432 domain = domain.substr(1); 432 domain = domain.substr(1);
433 } 433 }
434 else 434 else
435 { 435 {
436 include = true; 436 include = true;
437 hasIncludes = true; 437 hasIncludes = true;
438 } 438 }
439 439
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(/\.+$/, "").toUpperCase();
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(/\.+$/, "").toUpperCase();
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;
525 } 525 }
526 } 526 }
527 527
528 return true; 528 return true;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 * @param {string} [sitekeys] 576 * @param {string} [sitekeys]
577 * Public keys of websites that this filter should apply to 577 * Public keys of websites that this filter should apply to
578 * @constructor 578 * @constructor
579 * @augments ActiveFilter 579 * @augments ActiveFilter
580 */ 580 */
581 function RegExpFilter(text, regexpSource, contentType, matchCase, domains, 581 function RegExpFilter(text, regexpSource, contentType, matchCase, domains,
582 thirdParty, sitekeys) 582 thirdParty, sitekeys)
583 { 583 {
584 ActiveFilter.call(this, text, domains, sitekeys); 584 ActiveFilter.call(this, text, domains, sitekeys);
585 585
586 if (contentType != null) 586 if (contentType !== null)
587 this.contentType = contentType; 587 this.contentType = contentType;
588 if (matchCase) 588 if (matchCase)
589 this.matchCase = matchCase; 589 this.matchCase = matchCase;
590 if (thirdParty != null) 590 if (thirdParty !== null)
591 this.thirdParty = thirdParty; 591 this.thirdParty = thirdParty;
592 if (sitekeys != null) 592 if (sitekeys !== null)
593 this.sitekeySource = sitekeys; 593 this.sitekeySource = sitekeys;
594 594
595 if (regexpSource.length >= 2 && 595 if (regexpSource.length >= 2 &&
596 regexpSource[0] == "/" && 596 regexpSource[0] === "/" &&
597 regexpSource[regexpSource.length - 1] == "/") 597 regexpSource[regexpSource.length - 1] === "/")
598 { 598 {
599 // The filter is a regular expression - convert it immediately to 599 // The filter is a regular expression - convert it immediately to
600 // catch syntax errors 600 // catch syntax errors
601 let regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2), 601 let regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2),
602 this.matchCase ? "" : "i"); 602 this.matchCase ? "" : "i");
603 Object.defineProperty(this, "regexp", {value: regexp}); 603 Object.defineProperty(this, "regexp", {value: regexp});
604 } 604 }
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
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 * @param {number} typeMask bitmask of content / request types to match 696 * @param {number} typeMask bitmask of content / request types to match
697 * @param {string} [docDomain] domain name of the document that loads the URL 697 * @param {string} [docDomain] domain name of the document that loads the URL
698 * @param {boolean} [thirdParty] should be true if the URL is a third-party 698 * @param {boolean} [thirdParty] should be true if the URL is a third-party
699 * request 699 * request
700 * @param {string} [sitekey] public key provided by the document 700 * @param {string} [sitekey] public key provided by the document
701 * @return {boolean} true in case of a match 701 * @return {boolean} true in case of a match
702 */ 702 */
703 matches(location, typeMask, docDomain, thirdParty, sitekey) 703 matches(location, typeMask, docDomain, thirdParty, sitekey)
704 { 704 {
705 if (this.contentType & typeMask && 705 if (this.contentType & typeMask &&
706 (this.thirdParty == null || this.thirdParty == thirdParty) && 706 (this.thirdParty === null || this.thirdParty === thirdParty) &&
707 this.isActiveOnDomain(docDomain, sitekey) && this.regexp.test(location)) 707 this.isActiveOnDomain(docDomain, sitekey) && this.regexp.test(location))
708 { 708 {
709 return true; 709 return true;
710 } 710 }
711 return false; 711 return false;
712 } 712 }
713 }); 713 });
714 714
715 // Required to optimize Matcher, see also RegExpFilter.prototype.length 715 // Required to optimize Matcher, see also RegExpFilter.prototype.length
716 Object.defineProperty(RegExpFilter.prototype, "0", { 716 Object.defineProperty(RegExpFilter.prototype, "0", {
717 get() { return this; } 717 get() { return this; }
718 }); 718 });
719 719
720 /** 720 /**
721 * Creates a RegExp filter from its text representation 721 * Creates a RegExp filter from its text representation
722 * @param {string} text same as in Filter() 722 * @param {string} text same as in Filter()
723 * @return {Filter} 723 * @return {Filter}
724 */ 724 */
725 RegExpFilter.fromText = function(text) 725 RegExpFilter.fromText = function(text)
726 { 726 {
727 let blocking = true; 727 let blocking = true;
728 let origText = text; 728 let origText = text;
729 if (text[0] == "@" && text[1] == "@") 729 if (text[0] === "@" && text[1] === "@")
730 { 730 {
731 blocking = false; 731 blocking = false;
732 text = text.substr(2); 732 text = text.substr(2);
733 } 733 }
734 734
735 let contentType = null; 735 let contentType = null;
736 let matchCase = null; 736 let matchCase = null;
737 let domains = null; 737 let domains = null;
738 let sitekeys = null; 738 let sitekeys = null;
739 let thirdParty = null; 739 let thirdParty = null;
(...skipping 13 matching lines...) Expand all
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 option = option.replace(/-/, "_").toUpperCase();
759 if (option in RegExpFilter.typeMap) 759 if (option in RegExpFilter.typeMap)
760 { 760 {
761 contentType |= RegExpFilter.typeMap[option]; 761 contentType |= RegExpFilter.typeMap[option];
762 762
763 if (option == "CSP" && value) 763 if (option === "CSP" && value)
764 csp = value; 764 csp = value;
765 } 765 }
766 else if (option[0] == "~" && option.substr(1) in RegExpFilter.typeMap) 766 else if (option[0] === "~" && option.substr(1) in RegExpFilter.typeMap)
767 { 767 {
768 if (contentType == null) 768 if (contentType === null)
769 ({contentType} = RegExpFilter.prototype); 769 ({contentType} = RegExpFilter.prototype);
770 contentType &= ~RegExpFilter.typeMap[option.substr(1)]; 770 contentType &= ~RegExpFilter.typeMap[option.substr(1)];
771 } 771 }
772 else if (option == "MATCH_CASE") 772 else if (option === "MATCH_CASE")
773 matchCase = true; 773 matchCase = true;
774 else if (option == "~MATCH_CASE") 774 else if (option === "~MATCH_CASE")
775 matchCase = false; 775 matchCase = false;
776 else if (option == "DOMAIN" && value) 776 else if (option === "DOMAIN" && value)
777 domains = value.toUpperCase(); 777 domains = value.toUpperCase();
778 else if (option == "THIRD_PARTY") 778 else if (option === "THIRD_PARTY")
779 thirdParty = true; 779 thirdParty = true;
780 else if (option == "~THIRD_PARTY") 780 else if (option === "~THIRD_PARTY")
781 thirdParty = false; 781 thirdParty = false;
782 else if (option == "COLLAPSE") 782 else if (option === "COLLAPSE")
783 collapse = true; 783 collapse = true;
784 else if (option == "~COLLAPSE") 784 else if (option === "~COLLAPSE")
785 collapse = false; 785 collapse = false;
786 else if (option == "SITEKEY" && value) 786 else if (option === "SITEKEY" && value)
787 sitekeys = value.toUpperCase(); 787 sitekeys = value.toUpperCase();
788 else if (option == "REWRITE" && value) 788 else if (option === "REWRITE" && value)
789 rewrite = value; 789 rewrite = value;
790 else 790 else
791 return new InvalidFilter(origText, "filter_unknown_option"); 791 return new InvalidFilter(origText, "filter_unknown_option");
792 } 792 }
793 } 793 }
794 794
795 // For security reasons, never match $rewrite filters 795 // For security reasons, never match $rewrite filters
796 // against requests that might load any code to be executed. 796 // against requests that might load any code to be executed.
797 if (rewrite != null) 797 if (rewrite !== null)
798 { 798 {
799 if (contentType == null) 799 if (contentType === null)
800 ({contentType} = RegExpFilter.prototype); 800 ({contentType} = RegExpFilter.prototype);
801 contentType &= ~(RegExpFilter.typeMap.SCRIPT | 801 contentType &= ~(RegExpFilter.typeMap.SCRIPT |
802 RegExpFilter.typeMap.SUBDOCUMENT | 802 RegExpFilter.typeMap.SUBDOCUMENT |
803 RegExpFilter.typeMap.OBJECT | 803 RegExpFilter.typeMap.OBJECT |
804 RegExpFilter.typeMap.OBJECT_SUBREQUEST); 804 RegExpFilter.typeMap.OBJECT_SUBREQUEST);
805 } 805 }
806 806
807 try 807 try
808 { 808 {
809 if (blocking) 809 if (blocking)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 * BlockingFilter.prototype.rewrite. 880 * BlockingFilter.prototype.rewrite.
881 * @constructor 881 * @constructor
882 * @augments RegExpFilter 882 * @augments RegExpFilter
883 */ 883 */
884 function BlockingFilter(text, regexpSource, contentType, matchCase, domains, 884 function BlockingFilter(text, regexpSource, contentType, matchCase, domains,
885 thirdParty, sitekeys, collapse, csp, rewrite) 885 thirdParty, sitekeys, collapse, csp, rewrite)
886 { 886 {
887 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, 887 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains,
888 thirdParty, sitekeys); 888 thirdParty, sitekeys);
889 889
890 if (collapse != null) 890 if (collapse !== null)
891 this.collapse = collapse; 891 this.collapse = collapse;
892 892
893 if (csp != null) 893 if (csp !== null)
894 this.csp = csp; 894 this.csp = csp;
895 895
896 if (rewrite != null) 896 if (rewrite !== null)
897 this.rewrite = rewrite; 897 this.rewrite = rewrite;
898 } 898 }
899 exports.BlockingFilter = BlockingFilter; 899 exports.BlockingFilter = BlockingFilter;
900 900
901 BlockingFilter.prototype = extend(RegExpFilter, { 901 BlockingFilter.prototype = extend(RegExpFilter, {
902 type: "blocking", 902 type: "blocking",
903 903
904 /** 904 /**
905 * Defines whether the filter should collapse blocked content. 905 * Defines whether the filter should collapse blocked content.
906 * Can be null (use the global preference). 906 * Can be null (use the global preference).
(...skipping 17 matching lines...) Expand all
924 /** 924 /**
925 * Rewrites an URL. 925 * Rewrites an URL.
926 * @param {string} url the URL to rewrite 926 * @param {string} url the URL to rewrite
927 * @return {string} the rewritten URL, or the original in case of failure 927 * @return {string} the rewritten URL, or the original in case of failure
928 */ 928 */
929 rewriteUrl(url) 929 rewriteUrl(url)
930 { 930 {
931 try 931 try
932 { 932 {
933 let rewrittenUrl = new URL(url.replace(this.regexp, this.rewrite), url); 933 let rewrittenUrl = new URL(url.replace(this.regexp, this.rewrite), url);
934 if (rewrittenUrl.origin == new URL(url).origin) 934 if (rewrittenUrl.origin === new URL(url).origin)
935 return rewrittenUrl.href; 935 return rewrittenUrl.href;
936 } 936 }
937 catch (e) 937 catch (e)
938 { 938 {
939 } 939 }
940 940
941 return url; 941 return url;
942 } 942 }
943 }); 943 });
944 944
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 * ElemHideEmulationFilter|InvalidFilter} 1011 * ElemHideEmulationFilter|InvalidFilter}
1012 */ 1012 */
1013 ElemHideBase.fromText = function(text, domains, type, selector) 1013 ElemHideBase.fromText = function(text, domains, type, selector)
1014 { 1014 {
1015 // We don't allow ElemHide filters which have any empty domains. 1015 // We don't allow ElemHide filters which have any empty domains.
1016 // Note: The ElemHide.prototype.domainSeparator is duplicated here, if that 1016 // Note: The ElemHide.prototype.domainSeparator is duplicated here, if that
1017 // changes this must be changed too. 1017 // changes this must be changed too.
1018 if (domains && /(^|,)~?(,|$)/.test(domains)) 1018 if (domains && /(^|,)~?(,|$)/.test(domains))
1019 return new InvalidFilter(text, "filter_invalid_domain"); 1019 return new InvalidFilter(text, "filter_invalid_domain");
1020 1020
1021 if (type == "@") 1021 if (type === "@")
1022 return new ElemHideException(text, domains, selector); 1022 return new ElemHideException(text, domains, selector);
1023 1023
1024 if (type == "?") 1024 if (type === "?")
1025 { 1025 {
1026 // Element hiding emulation filters are inefficient so we need to make sure 1026 // Element hiding emulation filters are inefficient so we need to make sure
1027 // that they're only applied if they specify active domains 1027 // that they're only applied if they specify active domains
1028 if (!/,[^~][^,.]*\.[^,]/.test("," + domains)) 1028 if (!/,[^~][^,.]*\.[^,]/.test("," + domains))
1029 return new InvalidFilter(text, "filter_elemhideemulation_nodomain"); 1029 return new InvalidFilter(text, "filter_elemhideemulation_nodomain");
1030 1030
1031 return new ElemHideEmulationFilter(text, domains, selector); 1031 return new ElemHideEmulationFilter(text, domains, selector);
1032 } 1032 }
1033 1033
1034 return new ElemHideFilter(text, domains, selector); 1034 return new ElemHideFilter(text, domains, selector);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 */ 1080 */
1081 function ElemHideEmulationFilter(text, domains, selector) 1081 function ElemHideEmulationFilter(text, domains, selector)
1082 { 1082 {
1083 ElemHideBase.call(this, text, domains, selector); 1083 ElemHideBase.call(this, text, domains, selector);
1084 } 1084 }
1085 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; 1085 exports.ElemHideEmulationFilter = ElemHideEmulationFilter;
1086 1086
1087 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { 1087 ElemHideEmulationFilter.prototype = extend(ElemHideBase, {
1088 type: "elemhideemulation" 1088 type: "elemhideemulation"
1089 }); 1089 });
OLDNEW
« no previous file with comments | « lib/events.js ('k') | lib/filterListener.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld