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

Side by Side Diff: compiled/filter/ElemHideBase.cpp

Issue 29600641: Issue 5175 - Reject element hiding filter with empty domain names (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebased patch. Created March 6, 2018, 7:32 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 | « compiled/filter/ElemHideBase.h ('k') | compiled/filter/ElemHideEmulationFilter.h » ('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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 static constexpr String::value_type ELEM_HIDE_EMULATION_DELIMITER[] = u"#?#"; 59 static constexpr String::value_type ELEM_HIDE_EMULATION_DELIMITER[] = u"#?#";
60 static constexpr String::size_type ELEM_HIDE_EMULATION_DELIMITER_LEN = str_len gth_of(ELEM_HIDE_EMULATION_DELIMITER); 60 static constexpr String::size_type ELEM_HIDE_EMULATION_DELIMITER_LEN = str_len gth_of(ELEM_HIDE_EMULATION_DELIMITER);
61 61
62 static constexpr String::value_type OLD_PROPS_SELECTOR[] = u"[-abp-properties= "; 62 static constexpr String::value_type OLD_PROPS_SELECTOR[] = u"[-abp-properties= ";
63 static constexpr String::size_type OLD_PROPS_SELECTOR_LEN = str_length_of(OLD_ PROPS_SELECTOR); 63 static constexpr String::size_type OLD_PROPS_SELECTOR_LEN = str_length_of(OLD_ PROPS_SELECTOR);
64 64
65 static constexpr String::value_type PROPS_SELECTOR[] = u":-abp-properties("; 65 static constexpr String::value_type PROPS_SELECTOR[] = u":-abp-properties(";
66 static constexpr String::size_type PROPS_SELECTOR_LEN = str_length_of(PROPS_SE LECTOR); 66 static constexpr String::size_type PROPS_SELECTOR_LEN = str_length_of(PROPS_SE LECTOR);
67 } 67 }
68 68
69 ElemHideBase::ElemHideBase(Type type, const String& text, const ElemHideData& da ta) 69 ElemHideBase::ElemHideBase(Type type, const String& text, const ElemHideData& da ta, const ParsedDomains& parsedDomains)
70 : ActiveFilter(type, text, false), mData(data) 70 : ActiveFilter(type, text, false), mData(data)
71 { 71 {
72 if (mData.HasDomains()) 72 if (mData.HasDomains())
73 ParseDomains(mData.GetDomainsSource(mText), u','); 73 FillDomains(mData.GetDomainsSource(mText), parsedDomains);
74 } 74 }
75 75
76 Filter::Type ElemHideBase::Parse(DependentString& text, ElemHideData& data, bool & needConversion) 76 Filter::Type ElemHideBase::Parse(DependentString& text, DependentString& error,
77 ElemHideData& data, bool& needConversion,
78 ParsedDomains& parsedDomains)
77 { 79 {
78 needConversion = false; 80 needConversion = false;
79 81
80 StringScanner scanner(text); 82 StringScanner scanner(text);
81 83
82 // Domains part 84 // Domains part
83 bool seenSpaces = false; 85 bool seenSpaces = false;
84 while (!scanner.done()) 86 while (!scanner.done())
85 { 87 {
86 String::value_type next = scanner.next(); 88 String::value_type next = scanner.next();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 if (scanner.done()) 126 if (scanner.done())
125 return Type::UNKNOWN; 127 return Type::UNKNOWN;
126 128
127 data.mSelectorStart = scanner.position() + 1; 129 data.mSelectorStart = scanner.position() + 1;
128 130
129 // We are done validating, now we can normalize whitespace and the domain part 131 // We are done validating, now we can normalize whitespace and the domain part
130 if (seenSpaces) 132 if (seenSpaces)
131 NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart); 133 NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart);
132 DependentString(text, 0, data.mDomainsEnd).toLower(); 134 DependentString(text, 0, data.mDomainsEnd).toLower();
133 135
136 parsedDomains =
137 ParseDomainsInternal(data.GetDomainsSource(text), u',', false);
138 if (parsedDomains.hasEmpty)
139 {
140 error = u"filter_invalid_domain"_str;
141 return Type::INVALID;
142 }
134 // We still need to check the old syntax. It will be converted when 143 // We still need to check the old syntax. It will be converted when
135 // we instantiate the filter. 144 // we instantiate the filter.
136 if (!emulation && 145 if (!emulation &&
137 text.find(OLD_PROPS_SELECTOR, data.mSelectorStart, OLD_PROPS_SELECTOR_LEN) != text.npos) 146 text.find(OLD_PROPS_SELECTOR, data.mSelectorStart, OLD_PROPS_SELECTOR_LEN) != text.npos)
138 { 147 {
139 needConversion = true; 148 needConversion = true;
140 emulation = !exception; 149 emulation = !exception;
141 } 150 }
142 151
143 if (exception) 152 if (exception)
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 if (item.second && !item.first.empty()) 341 if (item.second && !item.first.empty())
333 { 342 {
334 if (!result.empty()) 343 if (!result.empty())
335 result.append(u','); 344 result.append(u',');
336 result.append(item.first); 345 result.append(item.first);
337 } 346 }
338 } 347 }
339 } 348 }
340 return result; 349 return result;
341 } 350 }
OLDNEW
« no previous file with comments | « compiled/filter/ElemHideBase.h ('k') | compiled/filter/ElemHideEmulationFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld