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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 return Type::UNKNOWN; 96 return Type::UNKNOWN;
97 97
98 // Selector part 98 // Selector part
99 99
100 // Selector shouldn't be empty 100 // Selector shouldn't be empty
101 seenSpaces |= scanner.skip(u' '); 101 seenSpaces |= scanner.skip(u' ');
102 if (scanner.done()) 102 if (scanner.done())
103 return Type::UNKNOWN; 103 return Type::UNKNOWN;
104 104
105 data.mSelectorStart = scanner.position() + 1; 105 data.mSelectorStart = scanner.position() + 1;
106 while (!scanner.done())
107 {
108 switch (scanner.next())
109 {
110 case u'{':
111 case u'}':
112 return Type::UNKNOWN;
113 }
114 }
115 106
116 // We are done validating, now we can normalize whitespace and the domain part 107 // We are done validating, now we can normalize whitespace and the domain part
117 if (seenSpaces) 108 if (seenSpaces)
118 NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart); 109 NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart);
119 DependentString(text, 0, data.mDomainsEnd).toLower(); 110 DependentString(text, 0, data.mDomainsEnd).toLower();
120 111
121 if (exception) 112 if (exception)
122 return Type::ELEMHIDEEXCEPTION; 113 return Type::ELEMHIDEEXCEPTION;
123 114
124 if (text.find(u"[-abp-properties="_str, data.mSelectorStart) != text.npos) 115 if (text.find(u"[-abp-properties="_str, data.mSelectorStart) != text.npos)
125 return Type::ELEMHIDEEMULATION; 116 return Type::ELEMHIDEEMULATION;
126 117
127 return Type::ELEMHIDE; 118 return Type::ELEMHIDE;
128 } 119 }
129 120
121 namespace {
122
123 OwnedString EscapeCurlies(String::size_type first, const DependentString& str)
124 {
125 OwnedString result;
126
127 String::size_type start = 0;
128 String::size_type i = first;
129 for (; i < str.length(); i++)
130 {
131 if (str[i] == '}' || str[i] == '{')
132 {
133 if (i != start)
134 result.append(str.data() + start, i - start);
135 start = i + 1;
136 switch(str[i])
137 {
138 case '}':
139 result.append("\\x7D ", 5);
140 break;
141 case '{':
142 result.append("\\x7B ", 5);
143 break;
144 default:
145 break;
146 }
147 }
148 }
149 if (start < i)
150 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.
151 return result;
152 }
153
154 }
155
156 OwnedString ElemHideBase::GetSelector() const
157 {
158 DependentString selector = mData.GetSelector(mText);
159
160 for (String::size_type i = 0; i < selector.length(); i++)
161 if (selector[i] == '}' || selector[i] == '{')
162 return EscapeCurlies(i, selector);
163
164 return OwnedString(selector);
165 }
166
130 OwnedString ElemHideBase::GetSelectorDomain() const 167 OwnedString ElemHideBase::GetSelectorDomain() const
131 { 168 {
132 /* TODO this is inefficient */ 169 /* TODO this is inefficient */
133 OwnedString result; 170 OwnedString result;
134 if (mDomains) 171 if (mDomains)
135 { 172 {
136 for (const auto& item : *mDomains) 173 for (const auto& item : *mDomains)
137 { 174 {
138 if (item.second && !item.first.empty()) 175 if (item.second && !item.first.empty())
139 { 176 {
140 if (!result.empty()) 177 if (!result.empty())
141 result.append(u','); 178 result.append(u',');
142 result.append(item.first); 179 result.append(item.first);
143 } 180 }
144 } 181 }
145 } 182 }
146 return result; 183 return result;
147 } 184 }
OLDNEW
« 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