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) |
{ |