Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: compiled/filter/Filter.cpp

Issue 29595633: Issue 5870 - Implement the new ElemHideEmulation filter type (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Review comments Created Feb. 13, 2018, 3:53 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « compiled/filter/ElemHideBase.cpp ('k') | meson.build » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
+ 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();
}
« no previous file with comments | « compiled/filter/ElemHideBase.cpp ('k') | meson.build » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld