| Index: compiled/filter/Filter.cpp |
| =================================================================== |
| --- a/compiled/filter/Filter.cpp |
| +++ b/compiled/filter/Filter.cpp |
| @@ -101,24 +101,32 @@ |
| // Parsing also normalizes the filter text, so it has to be done before the |
| // lookup in knownFilters. |
| union |
| { |
| RegExpFilterData regexp; |
| ElemHideData elemhide; |
| } data; |
| + bool needConversion = false; |
| DependentString error; |
| Filter::Type type = CommentFilter::Parse(text); |
| if (type == Filter::Type::UNKNOWN) |
| - type = ElemHideBase::Parse(text, data.elemhide); |
| + type = ElemHideBase::Parse(text, data.elemhide, needConversion); |
| if (type == Filter::Type::UNKNOWN) |
| type = RegExpFilter::Parse(text, error, data.regexp); |
| + if (needConversion && (type == ElemHideException::classType || type == ElemHideEmulationFilter::classType)) |
|
sergei
2018/02/12 12:53:20
Firstly I thought about moving of `(type == ElemHi
hub
2018/02/12 18:14:40
I was being overly paranoid.
Done.
|
| + text = ElemHideBase::ConvertFilter(text, data.elemhide.mSelectorStart); |
| + |
| + // At that point we failed the conversion. |
| + if (text.empty()) |
| + return nullptr; |
| + |
| auto knownFilter = knownFilters.find(text); |
| if (knownFilter) |
| { |
| knownFilter->second->AddRef(); |
| return knownFilter->second; |
| } |
| FilterPtr filter; |
| @@ -147,17 +155,20 @@ |
| if (static_cast<ElemHideEmulationFilter*>(filter.get())->IsGeneric()) |
| filter = FilterPtr(new InvalidFilter(text, u"filter_elemhideemulation_nodomain"_str), false); |
| break; |
| default: |
| // This should never happen but just in case |
| return nullptr; |
| } |
| - // This is a hack: we looked up the entry using text but create it using |
| - // filter->mText. This works because both are equal at this point. However, |
| - // text refers to a temporary buffer which will go away. |
| enter_context("Adding to known filters"); |
| - knownFilter.assign(filter->mText, filter.get()); |
| + if (text != filter->mText) |
| + knownFilters[filter->mText] = filter.get(); |
| + else |
| + // This is a hack: we looked up the entry using text but create it using |
| + // filter->mText. This works because both are equal at this point. However, |
| + // text refers to a temporary buffer which will go away. |
| + knownFilter.assign(filter->mText, filter.get()); |
| exit_context(); |
| return filter.release(); |
| } |