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

Delta Between Two Patch Sets: compiled/filter/ElemHideBase.cpp

Issue 29595633: Issue 5870 - Implement the new ElemHideEmulation filter type (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Review comments Created Feb. 13, 2018, 3:53 p.m.
Right Patch Set: Deal with ill formed filters. Created Feb. 14, 2018, 5:05 p.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 | « compiled/filter/ElemHideBase.h ('k') | compiled/filter/Filter.cpp » ('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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)
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 ParseDomains(mData.GetDomainsSource(mText), u',');
74 } 74 }
75 75
76 Filter::Type ElemHideBase::Parse(DependentString& text, ElemHideData& data, bool & needConversion) 76 Filter::Type ElemHideBase::Parse(DependentString& text, ElemHideData& data, bool & needConversion)
77 { 77 {
78 needConversion = false;
79
78 StringScanner scanner(text); 80 StringScanner scanner(text);
79
80 needConversion = false;
81 81
82 // Domains part 82 // Domains part
83 bool seenSpaces = false; 83 bool seenSpaces = false;
84 while (!scanner.done()) 84 while (!scanner.done())
85 { 85 {
86 String::value_type next = scanner.next(); 86 String::value_type next = scanner.next();
87 if (next == u'#') 87 if (next == u'#')
88 { 88 {
89 data.mDomainsEnd = scanner.position(); 89 data.mDomainsEnd = scanner.position();
90 break; 90 break;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 switch (c) 184 switch (c)
185 { 185 {
186 case u'"': 186 case u'"':
187 case u'\'': 187 case u'\'':
188 if (quote == 0) 188 if (quote == 0)
189 { 189 {
190 // syntax error: we already have a quoted section. 190 // syntax error: we already have a quoted section.
191 if (properties.end) 191 if (properties.end)
192 return DependentString(); 192 return DependentString();
193 193
194 if (properties.start != index)
195 return DependentString();
196
194 quote = c; 197 quote = c;
195 properties.start = index + 1; 198 properties.start = index + 1;
196 } 199 }
197 else if (quote == c) 200 else if (quote == c)
198 { 201 {
199 // end of quoted. 202 // end of quoted.
200 quote = 0; 203 quote = 0;
201 properties.end = index; 204 properties.end = index;
202 } 205 }
203 break; 206 break;
204 case u']': 207 case u']':
205 if (quote == 0) 208 if (quote == 0)
206 { 209 {
207 if (properties.end == 0) 210 if (properties.end == 0)
211 return DependentString();
212 if (properties.end + 1 != index)
208 return DependentString(); 213 return DependentString();
209 suffix.start = index + 1; 214 suffix.start = index + 1;
210 } 215 }
211 break; 216 break;
212 default: 217 default:
213 break; 218 break;
214 } 219 }
215 } 220 }
216 221
217 if (suffix.start == at) 222 if (suffix.start == at)
sergei 2018/02/27 10:56:53 Just for reference, I think it (what the whole for
218 return DependentString(); 223 return DependentString();
219 224
220 String::size_type delimiter = text.find(ELEM_HIDE_DELIMITER, 0, 225 String::size_type delimiter = text.find(ELEM_HIDE_DELIMITER, 0,
221 ELEM_HIDE_DELIMITER_LEN); 226 ELEM_HIDE_DELIMITER_LEN);
222 // +1 for the replacement of "##" by "#?#" 227 // +1 for the replacement of "##" by "#?#"
223 if (delimiter != text.npos) 228 if (delimiter != text.npos)
224 at++; 229 at++;
225 auto new_len = at + prefix.len() + PROPS_SELECTOR_LEN + properties.len() + 1 / * ) */ + suffix.len(); 230 auto new_len = at + prefix.len() + PROPS_SELECTOR_LEN + properties.len() + 1 / * ) */ + suffix.len();
226 231
227 assert2(new_len + 1 == length || (delimiter == text.npos && new_len + 2 == len gth), u"Inconsistent length in filter conversion."_str); 232 assert2(new_len + 1 == length || (delimiter == text.npos && new_len + 2 == len gth), u"Inconsistent length in filter conversion."_str);
sergei 2018/02/27 10:56:53 not important just for reference length == new_len
hub 2018/02/27 13:32:30 Acknowledged.
228 233
229 DependentString converted(text, 0, new_len); 234 DependentString converted(text, 0, new_len);
230 235
231 if (suffix.len()) 236 if (suffix.len())
232 { 237 {
233 new_len -= suffix.len(); 238 new_len -= suffix.len();
234 std::memmove(converted.data() + new_len, 239 std::memmove(converted.data() + new_len,
235 text.data() + suffix.start, 240 text.data() + suffix.start,
236 suffix.byte_len()); 241 suffix.byte_len());
237 } 242 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 if (item.second && !item.first.empty()) 332 if (item.second && !item.first.empty())
328 { 333 {
329 if (!result.empty()) 334 if (!result.empty())
330 result.append(u','); 335 result.append(u',');
331 result.append(item.first); 336 result.append(item.first);
332 } 337 }
333 } 338 }
334 } 339 }
335 return result; 340 return result;
336 } 341 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld