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

Side by Side Diff: compiled/filter/Filter.cpp

Issue 29600641: Issue 5175 - Reject element hiding filter with empty domain names (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebased Created Dec. 5, 2017, 6:06 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/ElemHideFilter.cpp ('k') | compiled/filter/RegExpFilter.cpp » ('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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 if (text.empty()) 97 if (text.empty())
98 return nullptr; 98 return nullptr;
99 99
100 // Parsing also normalizes the filter text, so it has to be done before the 100 // Parsing also normalizes the filter text, so it has to be done before the
101 // lookup in knownFilters. 101 // lookup in knownFilters.
102 union 102 union
103 { 103 {
104 RegExpFilterData regexp; 104 RegExpFilterData regexp;
105 ElemHideData elemhide; 105 ElemHideData elemhide;
106 } data; 106 } data;
107 ParsedDomains parsedDomains;
107 DependentString error; 108 DependentString error;
108 109
109 Filter::Type type = CommentFilter::Parse(text); 110 Filter::Type type = CommentFilter::Parse(text);
110 if (type == Filter::Type::UNKNOWN) 111 if (type == Filter::Type::UNKNOWN)
111 type = ElemHideBase::Parse(text, data.elemhide); 112 type = ElemHideBase::Parse(text, error, data.elemhide, parsedDomains);
112 if (type == Filter::Type::UNKNOWN) 113 if (type == Filter::Type::UNKNOWN)
113 type = RegExpFilter::Parse(text, error, data.regexp); 114 type = RegExpFilter::Parse(text, error, data.regexp);
114 115
115 auto knownFilter = knownFilters.find(text); 116 auto knownFilter = knownFilters.find(text);
116 if (knownFilter) 117 if (knownFilter)
117 { 118 {
118 knownFilter->second->AddRef(); 119 knownFilter->second->AddRef();
119 return knownFilter->second; 120 return knownFilter->second;
120 } 121 }
121 122
122 FilterPtr filter; 123 FilterPtr filter;
123 switch (type) 124 switch (type)
124 { 125 {
125 case CommentFilter::classType: 126 case CommentFilter::classType:
126 filter = FilterPtr(new CommentFilter(text), false); 127 filter = FilterPtr(new CommentFilter(text), false);
127 break; 128 break;
128 case InvalidFilter::classType: 129 case InvalidFilter::classType:
129 filter = FilterPtr(new InvalidFilter(text, error), false); 130 filter = FilterPtr(new InvalidFilter(text, error), false);
130 break; 131 break;
131 case BlockingFilter::classType: 132 case BlockingFilter::classType:
132 filter = FilterPtr(new BlockingFilter(text, data.regexp), false); 133 filter = FilterPtr(new BlockingFilter(text, data.regexp), false);
133 break; 134 break;
134 case WhitelistFilter::classType: 135 case WhitelistFilter::classType:
135 filter = FilterPtr(new WhitelistFilter(text, data.regexp), false); 136 filter = FilterPtr(new WhitelistFilter(text, data.regexp), false);
136 break; 137 break;
137 case ElemHideFilter::classType: 138 case ElemHideFilter::classType:
138 filter = FilterPtr(new ElemHideFilter(text, data.elemhide), false); 139 filter = FilterPtr(new ElemHideFilter(text, data.elemhide,
140 parsedDomains), false);
139 break; 141 break;
140 case ElemHideException::classType: 142 case ElemHideException::classType:
141 filter = FilterPtr(new ElemHideException(text, data.elemhide), false); 143 filter = FilterPtr(new ElemHideException(text, data.elemhide,
144 parsedDomains), false);
142 break; 145 break;
143 case ElemHideEmulationFilter::classType: 146 case ElemHideEmulationFilter::classType:
144 filter = FilterPtr(new ElemHideEmulationFilter(text, data.elemhide), false ); 147 filter = FilterPtr(new ElemHideEmulationFilter(text, data.elemhide,
148 parsedDomains), false);
145 if (static_cast<ElemHideEmulationFilter*>(filter.get())->IsGeneric()) 149 if (static_cast<ElemHideEmulationFilter*>(filter.get())->IsGeneric())
146 filter = FilterPtr(new InvalidFilter(text, u"filter_elemhideemulation_no domain"_str), false); 150 filter = FilterPtr(new InvalidFilter(text, u"filter_elemhideemulation_no domain"_str), false);
147 break; 151 break;
148 default: 152 default:
149 // This should never happen but just in case 153 // This should never happen but just in case
150 return nullptr; 154 return nullptr;
151 } 155 }
152 156
153 enter_context("Adding to known filters"); 157 enter_context("Adding to known filters");
154 if (text != filter->mText) 158 if (text != filter->mText)
155 knownFilters[filter->mText] = filter.get(); 159 knownFilters[filter->mText] = filter.get();
156 else 160 else
157 // This is a hack: we looked up the entry using text but create it using 161 // This is a hack: we looked up the entry using text but create it using
158 // filter->mText. This works because both are equal at this point. However, 162 // filter->mText. This works because both are equal at this point. However,
159 // text refers to a temporary buffer which will go away. 163 // text refers to a temporary buffer which will go away.
160 knownFilter.assign(filter->mText, filter.get()); 164 knownFilter.assign(filter->mText, filter.get());
161 exit_context(); 165 exit_context();
162 166
163 return filter.release(); 167 return filter.release();
164 } 168 }
OLDNEW
« no previous file with comments | « compiled/filter/ElemHideFilter.cpp ('k') | compiled/filter/RegExpFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld