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: Created Oct. 16, 2017, 5:10 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.h ('k') | test/filterClasses.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/filter/ElemHideBase.cpp
===================================================================
--- a/compiled/filter/ElemHideBase.cpp
+++ b/compiled/filter/ElemHideBase.cpp
@@ -98,40 +98,74 @@
// 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;
+ for (String::size_type i = first; 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;
+ }
+ }
+ }
+ 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') | no next file with comments »

Powered by Google App Engine
This is Rietveld