OLD | NEW |
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 Loading... |
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 case u'}': | 210 case u'}': |
209 return Type::UNKNOWN; | 211 return Type::UNKNOWN; |
210 } | 212 } |
211 } | 213 } |
212 | 214 |
213 // We are done validating, now we can normalize whitespace and the domain part | 215 // We are done validating, now we can normalize whitespace and the domain part |
214 if (seenSpaces) | 216 if (seenSpaces) |
215 NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart); | 217 NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart); |
216 DependentString(text, 0, data.mDomainsEnd).toLower(); | 218 DependentString(text, 0, data.mDomainsEnd).toLower(); |
217 | 219 |
| 220 parsedDomains = |
| 221 ParseDomainsInternal(data.GetDomainsSource(text), u',', false); |
| 222 if (parsedDomains.hasEmpty) |
| 223 { |
| 224 error = u"filter_invalid_domain"_str; |
| 225 return Type::INVALID; |
| 226 } |
| 227 |
218 if (exception) | 228 if (exception) |
219 return Type::ELEMHIDEEXCEPTION; | 229 return Type::ELEMHIDEEXCEPTION; |
220 | 230 |
221 if (emulation) | 231 if (emulation) |
222 return Type::ELEMHIDEEMULATION; | 232 return Type::ELEMHIDEEMULATION; |
223 | 233 |
224 return Type::ELEMHIDE; | 234 return Type::ELEMHIDE; |
225 } | 235 } |
226 | 236 |
227 OwnedString ElemHideBase::GetSelectorDomain() const | 237 OwnedString ElemHideBase::GetSelectorDomain() const |
228 { | 238 { |
229 /* TODO this is inefficient */ | 239 /* TODO this is inefficient */ |
230 OwnedString result; | 240 OwnedString result; |
231 if (mDomains) | 241 if (mDomains) |
232 { | 242 { |
233 for (const auto& item : *mDomains) | 243 for (const auto& item : *mDomains) |
234 { | 244 { |
235 if (item.second && !item.first.empty()) | 245 if (item.second && !item.first.empty()) |
236 { | 246 { |
237 if (!result.empty()) | 247 if (!result.empty()) |
238 result.append(u','); | 248 result.append(u','); |
239 result.append(item.first); | 249 result.append(item.first); |
240 } | 250 } |
241 } | 251 } |
242 } | 252 } |
243 return result; | 253 return result; |
244 } | 254 } |
OLD | NEW |