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

Unified Diff: compiled/filter/ElemHideBase.cpp

Issue 29580558: Issue 5174 - Allow '{' and '}' in selectors (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Fix a bug. Elememulation test case. Created Oct. 16, 2017, 6:38 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
Index: compiled/filter/ElemHideBase.cpp
===================================================================
--- a/compiled/filter/ElemHideBase.cpp
+++ b/compiled/filter/ElemHideBase.cpp
@@ -98,40 +98,77 @@
// Selector part
// Selector shouldn't be empty
seenSpaces |= scanner.skip(u' ');
if (scanner.done())
return Type::UNKNOWN;
data.mSelectorStart = scanner.position() + 1;
- while (!scanner.done())
- {
- switch (scanner.next())
- {
- case u'{':
- case u'}':
- return Type::UNKNOWN;
- }
- }
// We are done validating, now we can normalize whitespace and the domain part
if (seenSpaces)
NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart);
DependentString(text, 0, data.mDomainsEnd).toLower();
if (exception)
return Type::ELEMHIDEEXCEPTION;
if (text.find(u"[-abp-properties="_str, data.mSelectorStart) != text.npos)
return Type::ELEMHIDEEMULATION;
return Type::ELEMHIDE;
}
+namespace {
+
+OwnedString EscapeCurlies(String::size_type first, const DependentString& str)
+{
+ OwnedString result;
+
+ String::size_type start = 0;
+ String::size_type i = first;
+ for (; i < str.length(); i++)
+ {
+ if (str[i] == '}' || str[i] == '{')
+ {
+ if (i != start)
+ result.append(str.data() + start, i - start);
+ start = i + 1;
+ switch(str[i])
+ {
+ case '}':
+ result.append("\\x7D ", 5);
+ break;
+ case '{':
+ result.append("\\x7B ", 5);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ if (start < i)
+ result.append(str.data() + start, i - start);
Wladimir Palant 2017/10/17 10:24:33 This is performing lots of reallocations. Please c
hub 2017/10/17 19:22:18 Done.
+ return result;
+}
+
+}
+
+OwnedString ElemHideBase::GetSelector() const
+{
+ DependentString selector = mData.GetSelector(mText);
+
+ for (String::size_type i = 0; i < selector.length(); i++)
+ if (selector[i] == '}' || selector[i] == '{')
+ return EscapeCurlies(i, selector);
+
+ return OwnedString(selector);
+}
+
OwnedString ElemHideBase::GetSelectorDomain() const
{
/* TODO this is inefficient */
OwnedString result;
if (mDomains)
{
for (const auto& item : *mDomains)
{
« no previous file with comments | « compiled/filter/ElemHideBase.h ('k') | test/filterClasses.js » ('j') | test/filterClasses.js » ('J')

Powered by Google App Engine
This is Rietveld