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

Delta Between Two Patch Sets: lib/filterClasses.js

Issue 29680684: [$csp1 adblockpluscore] Issue 6329 - Allow whitespace in filter option values (Closed)
Left Patch Set: Created Jan. 26, 2018, 5:32 p.m.
Right Patch Set: Addressed some of Manish's initial feedback Created Feb. 13, 2018, 11:55 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | lib/synchronizer.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 */ 94 */
95 Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^, \s]+)?)*)?$/; 95 Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^, \s]+)?)*)?$/;
96 /** 96 /**
97 * Regular expression that options on a RegExp filter should match 97 * Regular expression that options on a RegExp filter should match
98 * @type {RegExp} 98 * @type {RegExp}
99 */ 99 */
100 Filter.optionsRegExp = /\$(~?[\w-]+(?:=[^,]+)?(?:,~?[\w-]+(?:=[^,]+)?)*)$/; 100 Filter.optionsRegExp = /\$(~?[\w-]+(?:=[^,]+)?(?:,~?[\w-]+(?:=[^,]+)?)*)$/;
101 101
102 /** 102 /**
103 * Creates a filter of correct type from its text representation - does the 103 * Creates a filter of correct type from its text representation - does the
104 * basic normalisation and parsing where possible before deferring to the right 104 * basic normalization and parsing where possible before deferring to the right
Manish Jethani 2018/02/05 16:09:57 I noticed that the documentation is now using the
kzar 2018/02/13 11:56:46 Kind of ironic heh, Done.
105 * constructor. 105 * constructor.
106 * @param {string} text as in Filter() 106 * @param {string} text as in Filter()
107 * @return {Filter} 107 * @return {Filter}
108 */ 108 */
109 Filter.fromText = function(text) 109 Filter.fromText = function(text)
110 { 110 {
111 let filter = Filter.knownFilters.get(text); 111 let filter = Filter.knownFilters.get(text);
Manish Jethani 2018/02/05 16:09:57 This means that two otherwise identical filters (p
kzar 2018/02/13 11:56:46 Any ideas? This whole change was a pain, perhaps t
Manish Jethani 2018/02/20 16:00:57 How about leaving the functions as they are, but c
Manish Jethani 2018/02/21 14:49:18 I meant of course: ... else if (textConta
kzar 2018/03/06 14:30:38 Well while I agree that doing filter normalisation
Manish Jethani 2018/03/07 00:13:55 You know my suggestion was way more specific than
Manish Jethani 2018/03/07 05:59:58 Another way to do it is by splitting on "csp=":
112 if (filter) 112 if (filter)
113 return filter; 113 return filter;
114 114
115 let match = (text.includes("#") ? Filter.elemhideRegExp.exec(text) : null); 115 let match = (text.includes("#") ? Filter.elemhideRegExp.exec(text) : null);
116 if (match) 116 if (match)
117 { 117 {
118 let [, domain, seperator, type, selector] = match; 118 let [, domain, seperator, type, selector] = match;
119 119
120 domain = domain.replace(/\s/g, ""); 120 domain = domain.replace(/\s/g, "");
121 selector = selector.trim(); 121 selector = selector.trim();
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 * @return {Filter} 701 * @return {Filter}
702 */ 702 */
703 RegExpFilter.fromText = function(text) 703 RegExpFilter.fromText = function(text)
704 { 704 {
705 let contentType = null; 705 let contentType = null;
706 let matchCase = null; 706 let matchCase = null;
707 let domains = null; 707 let domains = null;
708 let sitekeys = null; 708 let sitekeys = null;
709 let thirdParty = null; 709 let thirdParty = null;
710 let collapse = null; 710 let collapse = null;
711 let origText; 711 let origText = null;
Manish Jethani 2018/02/05 16:09:58 Why not initialize origText to null for consistenc
kzar 2018/02/13 11:56:46 Done.
712 712
713 let match = (text.indexOf("$") >= 0 ? Filter.optionsRegExp.exec(text) : null); 713 let match = (text.indexOf("$") >= 0 ? Filter.optionsRegExp.exec(text) : null);
714 if (!match) 714 if (!match)
715 { 715 {
716 origText = text = text.replace(/\s/g, ""); 716 origText = text = text.replace(/\s/g, "");
717 } 717 }
718 else 718 else
719 { 719 {
720 text = match.input.substring(0, match.index).replace(/\s/g, ""); 720 text = match.input.substring(0, match.index).replace(/\s/g, "");
721 let options = match[1].replace(/\s/g, ""); 721 let options = match[1].replace(/\s/g, "");
Manish Jethani 2018/02/05 16:09:58 I don't get this part. Doesn't this mean that "$cs
Manish Jethani 2018/02/06 05:14:39 I see, so the other patch builds on this. Got it.
kzar 2018/02/13 11:56:46 Sorry I should have left a comment on the review h
722 origText = text + "$" + options; 722 origText = text + "$" + options;
723 723
724 for (let option of options.toUpperCase().split(",")) 724 for (let option of options.toUpperCase().split(","))
725 { 725 {
726 let value = null; 726 let value = null;
727 let separatorIndex = option.indexOf("="); 727 let separatorIndex = option.indexOf("=");
728 if (separatorIndex >= 0) 728 if (separatorIndex >= 0)
729 { 729 {
730 value = option.substr(separatorIndex + 1); 730 value = option.substr(separatorIndex + 1);
731 option = option.substring(0, separatorIndex); 731 option = option.substring(0, separatorIndex);
Manish Jethani 2018/02/05 16:09:58 Any particular reason this is now using String.sub
kzar 2018/02/13 11:56:47 Well since I noticed that `substr` was being used
Manish Jethani 2018/02/20 16:00:57 Why is it a mistake to use substr? Anyway, the ch
732 } 732 }
733 option = option.replace(/-/, "_"); 733 option = option.replace(/-/, "_");
734 if (option in RegExpFilter.typeMap) 734 if (option in RegExpFilter.typeMap)
735 { 735 {
736 if (contentType == null) 736 if (contentType == null)
737 contentType = 0; 737 contentType = 0;
738 contentType |= RegExpFilter.typeMap[option]; 738 contentType |= RegExpFilter.typeMap[option];
739 } 739 }
740 else if (option[0] == "~" && option.substr(1) in RegExpFilter.typeMap) 740 else if (option[0] == "~" && option.substr(1) in RegExpFilter.typeMap)
741 { 741 {
(...skipping 27 matching lines...) Expand all
769 if (text.indexOf("@@") == 0) 769 if (text.indexOf("@@") == 0)
770 { 770 {
771 return new WhitelistFilter(origText, text.substr(2), contentType, 771 return new WhitelistFilter(origText, text.substr(2), contentType,
772 matchCase, domains, thirdParty, sitekeys); 772 matchCase, domains, thirdParty, sitekeys);
773 } 773 }
774 return new BlockingFilter(origText, text, contentType, matchCase, domains, 774 return new BlockingFilter(origText, text, contentType, matchCase, domains,
775 thirdParty, sitekeys, collapse); 775 thirdParty, sitekeys, collapse);
776 } 776 }
777 catch (e) 777 catch (e)
778 { 778 {
779 return new InvalidFilter(origText, "filter_invalid_regexp"); 779 return new InvalidFilter(origText, "filter_invalid_regexp");
Manish Jethani 2018/02/05 16:09:58 origText is no longer the original text so it has
kzar 2018/02/13 11:56:46 The point of `origText` is to show a more useful w
Manish Jethani 2018/02/20 16:00:57 What if we keep origText pointing to text as it wa
780 } 780 }
781 }; 781 };
782 782
783 /** 783 /**
784 * Maps type strings like "SCRIPT" or "OBJECT" to bit masks 784 * Maps type strings like "SCRIPT" or "OBJECT" to bit masks
785 */ 785 */
786 RegExpFilter.typeMap = { 786 RegExpFilter.typeMap = {
787 OTHER: 1, 787 OTHER: 1,
788 SCRIPT: 2, 788 SCRIPT: 2,
789 IMAGE: 4, 789 IMAGE: 4,
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 */ 1007 */
1008 function ElemHideEmulationFilter(text, domains, selector) 1008 function ElemHideEmulationFilter(text, domains, selector)
1009 { 1009 {
1010 ElemHideBase.call(this, text, domains, selector); 1010 ElemHideBase.call(this, text, domains, selector);
1011 } 1011 }
1012 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; 1012 exports.ElemHideEmulationFilter = ElemHideEmulationFilter;
1013 1013
1014 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { 1014 ElemHideEmulationFilter.prototype = extend(ElemHideBase, {
1015 type: "elemhideemulation" 1015 type: "elemhideemulation"
1016 }); 1016 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld