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: Created Oct. 16, 2017, 5:10 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
« no previous file with comments | « compiled/filter/ElemHideBase.h ('k') | test/filterClasses.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 for (String::size_type i = first; i < str.length(); i++)
129 {
130 if (str[i] == '}' || str[i] == '{')
131 {
132 if (i != start)
133 result.append(str.data() + start, i - start);
134 start = i + 1;
135 switch(str[i])
136 {
137 case '}':
138 result.append("\\x7D ", 5);
139 break;
140 case '{':
141 result.append("\\x7B ", 5);
142 break;
143 default:
144 break;
145 }
146 }
147 }
148 return result;
149 }
150
151 }
152
153 OwnedString ElemHideBase::GetSelector() const
154 {
155 DependentString selector = mData.GetSelector(mText);
156
157 for (String::size_type i = 0; i < selector.length(); i++)
158 if (selector[i] == '}' || selector[i] == '{')
159 return EscapeCurlies(i, selector);
160
161 return OwnedString(selector);
162 }
163
130 OwnedString ElemHideBase::GetSelectorDomain() const 164 OwnedString ElemHideBase::GetSelectorDomain() const
131 { 165 {
132 /* TODO this is inefficient */ 166 /* TODO this is inefficient */
133 OwnedString result; 167 OwnedString result;
134 if (mDomains) 168 if (mDomains)
135 { 169 {
136 for (const auto& item : *mDomains) 170 for (const auto& item : *mDomains)
137 { 171 {
138 if (item.second && !item.first.empty()) 172 if (item.second && !item.first.empty())
139 { 173 {
140 if (!result.empty()) 174 if (!result.empty())
141 result.append(u','); 175 result.append(u',');
142 result.append(item.first); 176 result.append(item.first);
143 } 177 }
144 } 178 }
145 } 179 }
146 return result; 180 return result;
147 } 181 }
OLDNEW
« 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