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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 = LENGTH_
OF(ELEM_HIDE_EMULATION_DELIMITER); | 60 static constexpr String::size_type ELEM_HIDE_EMULATION_DELIMITER_LEN = LENGTH_
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 = LENGTH_OF(OLD_PROP
S_SELECTOR); | 63 static constexpr String::size_type OLD_PROPS_SELECTOR_LEN = LENGTH_OF(OLD_PROP
S_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 = LENGTH_OF(PROPS_SELECT
OR); | 66 static constexpr String::size_type PROPS_SELECTOR_LEN = LENGTH_OF(PROPS_SELECT
OR); |
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 StringScanner scanner(text); | 80 StringScanner scanner(text); |
79 | 81 |
80 // Domains part | 82 // Domains part |
81 bool seenSpaces = false; | 83 bool seenSpaces = false; |
82 while (!scanner.done()) | 84 while (!scanner.done()) |
83 { | 85 { |
84 String::value_type next = scanner.next(); | 86 String::value_type next = scanner.next(); |
85 if (next == u'#') | 87 if (next == u'#') |
86 { | 88 { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 if (scanner.done()) | 124 if (scanner.done()) |
123 return Type::UNKNOWN; | 125 return Type::UNKNOWN; |
124 | 126 |
125 data.mSelectorStart = scanner.position() + 1; | 127 data.mSelectorStart = scanner.position() + 1; |
126 | 128 |
127 // We are done validating, now we can normalize whitespace and the domain part | 129 // We are done validating, now we can normalize whitespace and the domain part |
128 if (seenSpaces) | 130 if (seenSpaces) |
129 NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart); | 131 NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart); |
130 DependentString(text, 0, data.mDomainsEnd).toLower(); | 132 DependentString(text, 0, data.mDomainsEnd).toLower(); |
131 | 133 |
| 134 parsedDomains = |
| 135 ParseDomainsInternal(data.GetDomainsSource(text), u',', false); |
| 136 if (parsedDomains.hasEmpty) |
| 137 { |
| 138 error = u"filter_invalid_domain"_str; |
| 139 return Type::INVALID; |
| 140 } |
132 // We still need to check the old syntax. It will be converted when | 141 // We still need to check the old syntax. It will be converted when |
133 // we instantiate the filter. | 142 // we instantiate the filter. |
134 if (!emulation && | 143 if (!emulation && |
135 text.find(OLD_PROPS_SELECTOR, data.mSelectorStart, OLD_PROPS_SELECTOR_LEN)
!= text.npos) | 144 text.find(OLD_PROPS_SELECTOR, data.mSelectorStart, OLD_PROPS_SELECTOR_LEN)
!= text.npos) |
136 { | 145 { |
137 needConversion = true; | 146 needConversion = true; |
138 emulation = !exception; | 147 emulation = !exception; |
139 } | 148 } |
140 | 149 |
141 if (exception) | 150 if (exception) |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 if (item.second && !item.first.empty()) | 335 if (item.second && !item.first.empty()) |
327 { | 336 { |
328 if (!result.empty()) | 337 if (!result.empty()) |
329 result.append(u','); | 338 result.append(u','); |
330 result.append(item.first); | 339 result.append(item.first); |
331 } | 340 } |
332 } | 341 } |
333 } | 342 } |
334 return result; | 343 return result; |
335 } | 344 } |
OLD | NEW |