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 Created Dec. 5, 2017, 6:06 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 (length - end) * sizeof(String::value_type)); 135 (length - end) * sizeof(String::value_type));
136 offset += (length - end) * sizeof(String::value_type); 136 offset += (length - end) * sizeof(String::value_type);
137 137
138 return converted; 138 return converted;
139 } 139 }
140 140
141 return OwnedString(text); 141 return OwnedString(text);
142 } 142 }
143 } 143 }
144 144
145 ElemHideBase::ElemHideBase(Type type, const String& text, const ElemHideData& da ta) 145 ElemHideBase::ElemHideBase(Type type, const String& text,
146 const ElemHideData& data, const ParsedDomains& parsedDomains)
146 : ActiveFilter(type, ConvertFilter(text, data.mSelectorStart), false), 147 : ActiveFilter(type, ConvertFilter(text, data.mSelectorStart), false),
147 mData(data) 148 mData(data)
148 { 149 {
149 if (mData.HasDomains()) 150 if (mData.HasDomains())
150 ParseDomains(mData.GetDomainsSource(mText), u','); 151 FillDomains(mData.GetDomainsSource(mText), parsedDomains);
151 } 152 }
152 153
153 Filter::Type ElemHideBase::Parse(DependentString& text, ElemHideData& data) 154 Filter::Type ElemHideBase::Parse(DependentString& text, DependentString& error,
155 ElemHideData& data, ParsedDomains& parsedDomains)
154 { 156 {
155 StringScanner scanner(text); 157 StringScanner scanner(text);
156 158
157 // Domains part 159 // Domains part
158 bool seenSpaces = false; 160 bool seenSpaces = false;
159 while (!scanner.done()) 161 while (!scanner.done())
160 { 162 {
161 String::value_type next = scanner.next(); 163 String::value_type next = scanner.next();
162 if (next == u'#') 164 if (next == u'#')
163 { 165 {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 if (scanner.done()) 201 if (scanner.done())
200 return Type::UNKNOWN; 202 return Type::UNKNOWN;
201 203
202 data.mSelectorStart = scanner.position() + 1; 204 data.mSelectorStart = scanner.position() + 1;
203 205
204 // We are done validating, now we can normalize whitespace and the domain part 206 // We are done validating, now we can normalize whitespace and the domain part
205 if (seenSpaces) 207 if (seenSpaces)
206 NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart); 208 NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart);
207 DependentString(text, 0, data.mDomainsEnd).toLower(); 209 DependentString(text, 0, data.mDomainsEnd).toLower();
208 210
211 parsedDomains =
212 ParseDomainsInternal(data.GetDomainsSource(text), u',', false);
213 if (parsedDomains.hasEmpty)
214 {
215 error = u"filter_invalid_domain"_str;
216 return Type::INVALID;
217 }
218
209 if (exception) 219 if (exception)
210 return Type::ELEMHIDEEXCEPTION; 220 return Type::ELEMHIDEEXCEPTION;
211 221
212 if (emulation) 222 if (emulation)
213 return Type::ELEMHIDEEMULATION; 223 return Type::ELEMHIDEEMULATION;
214 224
215 return Type::ELEMHIDE; 225 return Type::ELEMHIDE;
216 } 226 }
217 227
218 namespace 228 namespace
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 if (item.second && !item.first.empty()) 286 if (item.second && !item.first.empty())
277 { 287 {
278 if (!result.empty()) 288 if (!result.empty())
279 result.append(u','); 289 result.append(u',');
280 result.append(item.first); 290 result.append(item.first);
281 } 291 }
282 } 292 }
283 } 293 }
284 return result; 294 return result;
285 } 295 }
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