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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 if (text.empty()) | 99 if (text.empty()) |
100 return nullptr; | 100 return nullptr; |
101 | 101 |
102 // Parsing also normalizes the filter text, so it has to be done before the | 102 // Parsing also normalizes the filter text, so it has to be done before the |
103 // lookup in knownFilters. | 103 // lookup in knownFilters. |
104 union | 104 union |
105 { | 105 { |
106 RegExpFilterData regexp; | 106 RegExpFilterData regexp; |
107 ElemHideData elemhide; | 107 ElemHideData elemhide; |
108 } data; | 108 } data; |
109 bool needConversion = false; | |
110 ParsedDomains parsedDomains; | 109 ParsedDomains parsedDomains; |
111 DependentString error; | 110 DependentString error; |
112 | 111 |
113 Filter::Type type = CommentFilter::Parse(text); | 112 Filter::Type type = CommentFilter::Parse(text); |
114 if (type == Filter::Type::UNKNOWN) | 113 if (type == Filter::Type::UNKNOWN) |
115 type = ElemHideBase::Parse(text, error, data.elemhide, needConversion, parse
dDomains); | 114 type = ElemHideBase::Parse(text, error, data.elemhide, parsedDomains); |
116 if (type == Filter::Type::UNKNOWN) | 115 if (type == Filter::Type::UNKNOWN) |
117 type = RegExpFilter::Parse(text, error, data.regexp); | 116 type = RegExpFilter::Parse(text, error, data.regexp); |
118 | 117 |
119 if (needConversion) | |
120 text = ElemHideBase::ConvertFilter(text, data.elemhide.mSelectorStart); | |
121 | |
122 // At that point we failed the conversion. | |
123 if (text.empty()) | |
124 return nullptr; | |
125 | |
126 auto knownFilter = knownFilters.find(text); | 118 auto knownFilter = knownFilters.find(text); |
127 if (knownFilter) | 119 if (knownFilter) |
128 { | 120 { |
129 knownFilter->second->AddRef(); | 121 knownFilter->second->AddRef(); |
130 return knownFilter->second; | 122 return knownFilter->second; |
131 } | 123 } |
132 | 124 |
133 FilterPtr filter; | 125 FilterPtr filter; |
134 switch (type) | 126 switch (type) |
135 { | 127 { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 knownFilters[filter->mText] = filter.get(); | 159 knownFilters[filter->mText] = filter.get(); |
168 else | 160 else |
169 // This is a hack: we looked up the entry using text but create it using | 161 // This is a hack: we looked up the entry using text but create it using |
170 // filter->mText. This works because both are equal at this point. However, | 162 // filter->mText. This works because both are equal at this point. However, |
171 // text refers to a temporary buffer which will go away. | 163 // text refers to a temporary buffer which will go away. |
172 knownFilter.assign(filter->mText, filter.get()); | 164 knownFilter.assign(filter->mText, filter.get()); |
173 exit_context(); | 165 exit_context(); |
174 | 166 |
175 return filter.release(); | 167 return filter.release(); |
176 } | 168 } |
OLD | NEW |