| Index: compiled/filter/ElemHideEmulationFilter.cpp |
| =================================================================== |
| --- a/compiled/filter/ElemHideEmulationFilter.cpp |
| +++ b/compiled/filter/ElemHideEmulationFilter.cpp |
| @@ -10,15 +10,110 @@ |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License |
| * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| */ |
| +#include <cstring> |
| + |
| #include "ElemHideEmulationFilter.h" |
| +namespace { |
| + // Convert filter from the old syntax to the new. |
| + OwnedString ConvertFilter(const String& text, String::size_type at) |
|
hub
2017/11/02 23:47:49
this is a bit rough conversion, but no RegExp. It
|
| + { |
| + static const auto propsSelector = u"[-abp-properties="_str; |
| + static const auto newPropsSelector = u":-abp-properties("_str; |
| + auto selectorPos = text.find(propsSelector, at); |
| + if (selectorPos != text.npos) |
| + { |
| + auto length = text.length(); |
| + auto properties = selectorPos + propsSelector.length(); |
| + String::value_type quote = 0; |
| + bool escape = false; |
| + String::size_type removed = 0; // how many chars we remove |
| + String::size_type end = properties; |
| + String::size_type quote_start = 0; |
| + String::size_type quote_end = 0; |
| + for (auto index = properties; |
| + index < length && end == properties; index++) |
| + { |
| + if (escape) |
| + { |
| + escape = false; |
| + continue; |
| + } |
| + |
| + auto c = text[index]; |
| + switch (c) |
| + { |
| + case '\\': |
| + escape = true; |
| + break; |
| + case '"': |
| + case '\'': |
| + if (quote == 0) |
| + { |
| + quote = c; |
| + quote_start = index + 1; |
| + } |
| + else if (quote == c) |
| + { |
| + // end of quoted. |
| + quote = 0; |
| + removed += 2; |
| + quote_end = index; |
| + } |
| + break; |
| + case ']': |
| + if (quote == 0) |
| + end = index + 1; // end of properties (after ]) |
| + break; |
| + default: |
| + break; |
| + } |
| + } |
| + |
| + if (quote != 0) |
| + quote_end = end - 1; |
| + else if (quote_end <= quote_start) |
| + { |
| + // we likely didn't find a quoted content so we just take it as is. |
| + quote_start = properties; |
| + quote_end = end - 1; |
| + } |
| + |
| + OwnedString converted(length - removed); |
| + String::size_type offset = 0; |
| + std::memcpy(converted.data(), text.data(), |
| + selectorPos * sizeof(String::value_type)); |
| + offset += selectorPos; |
| + |
| + std::memcpy(converted.data() + offset, newPropsSelector.data(), |
| + newPropsSelector.length() * sizeof(String::value_type)); |
| + offset += newPropsSelector.length(); |
| + |
| + std::memcpy(converted.data() + offset, text.data() + quote_start, |
| + (quote_end - quote_start) * sizeof(String::value_type)); |
| + offset += quote_end - quote_start; |
| + |
| + std::memcpy(converted.data() + offset, u")", sizeof(String::value_type)); |
| + offset++; |
| + |
| + std::memcpy(converted.data() + offset, text.data() + end, |
| + (length - end) * sizeof(String::value_type)); |
| + offset += (length - end) * sizeof(String::value_type); |
| + |
| + return converted; |
| + } |
| + |
| + return OwnedString(text); |
| + } |
| +} |
| + |
| ElemHideEmulationFilter::ElemHideEmulationFilter(const String& text, |
| const ElemHideData& data) |
| - : ElemHideBase(classType, text, data) |
| + : ElemHideBase(classType, ConvertFilter(text, data.mSelectorStart), data) |
|
hub
2017/11/02 23:47:49
I think the conversion should be done in the elemh
|
| { |
| } |