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

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

Issue 29600641: Issue 5175 - Reject element hiding filter with empty domain names (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebased patch. Created March 6, 2018, 7:32 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/ActiveFilter.h ('k') | compiled/filter/ElemHideBase.h » ('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 22 matching lines...) Expand all
33 ActiveFilter::DomainMap* ActiveFilter::GetDomains() const 33 ActiveFilter::DomainMap* ActiveFilter::GetDomains() const
34 { 34 {
35 return mDomains.get(); 35 return mDomains.get();
36 } 36 }
37 37
38 ActiveFilter::SitekeySet* ActiveFilter::GetSitekeys() const 38 ActiveFilter::SitekeySet* ActiveFilter::GetSitekeys() const
39 { 39 {
40 return mSitekeys.get(); 40 return mSitekeys.get();
41 } 41 }
42 42
43 void ActiveFilter::ParseDomains(const String& domains, 43 ParsedDomains ActiveFilter::ParseDomainsInternal(const String& domains,
44 String::value_type separator) const 44 String::value_type separator, bool ignoreTrailingDot)
45 { 45 {
46 DomainMap::size_type count = 2; 46 DomainMap::size_type count = 2;
47 for (String::size_type i = 0; i < domains.length(); i++) 47 for (String::size_type i = 0; i < domains.length(); i++)
48 if (domains[i] == separator) 48 if (domains[i] == separator)
49 count++; 49 count++;
50 50
51 mDomains.reset(new DomainMap(count));
52 annotate_address(mDomains.get(), "DomainMap");
53
54 StringScanner scanner(domains, 0, separator); 51 StringScanner scanner(domains, 0, separator);
55 String::size_type start = 0; 52 String::size_type start = 0;
56 bool reverse = false; 53 bool reverse = false;
57 bool hasIncludes = false; 54 ParsedDomains parsed;
55 parsed.hasIncludes = false;
56 parsed.domains.reserve(count);
58 bool done = scanner.done(); 57 bool done = scanner.done();
59 while (!done) 58 while (!done)
60 { 59 {
61 done = scanner.done(); 60 done = scanner.done();
62 String::value_type currChar = scanner.next(); 61 String::value_type currChar = scanner.next();
63 if (currChar == u'~' && scanner.position() == start) 62 if (currChar == u'~' && scanner.position() == start)
64 { 63 {
65 start++; 64 start++;
66 reverse = true; 65 reverse = true;
67 } 66 }
68 else if (currChar == separator) 67 else if (currChar == separator)
69 { 68 {
70 String::size_type len = scanner.position() - start; 69 String::size_type len = scanner.position() - start;
71 if (len > 0 && mIgnoreTrailingDot && domains[start + len - 1] == '.') 70 if (len > 0 && ignoreTrailingDot && domains[start + len - 1] == '.')
72 len--; 71 len--;
73 if (len > 0) 72 if (len > 0)
74 { 73 {
75 enter_context("Adding to ActiveFilter.mDomains"); 74 enter_context("Adding to ParsedDomains");
76 (*mDomains)[DependentString(domains, start, len)] = !reverse; 75 parsed.domains.push_back(
76 ParsedDomains::Domain({start, len, reverse}));
77 exit_context(); 77 exit_context();
78 78
79 if (!reverse) 79 if (!reverse)
80 hasIncludes = true; 80 parsed.hasIncludes = true;
81 } 81 }
82 else
83 parsed.hasEmpty = true;
82 start = scanner.position() + 1; 84 start = scanner.position() + 1;
83 reverse = false; 85 reverse = false;
84 } 86 }
85 } 87 }
86 enter_context("Adding to ActiveFilter.mDomains"); 88 return parsed;
87 (*mDomains)[DEFAULT_DOMAIN] = !hasIncludes; 89 }
90
91 void ActiveFilter::FillDomains(const String& domains, const ParsedDomains& parse d) const
92 {
93 mDomains.reset(new DomainMap(parsed.domains.size()));
94 annotate_address(mDomains.get(), "DomainMap");
95
96 for (auto d : parsed.domains)
97 {
98 enter_context("Adding to DomainMap");
99 (*mDomains)[DependentString(domains, d.pos, d.len)] = !d.reverse;
100 exit_context();
101 }
102 enter_context("Adding to DomainMap");
103 (*mDomains)[DEFAULT_DOMAIN] = !parsed.hasIncludes;
88 exit_context(); 104 exit_context();
89 } 105 }
90 106
107 void ActiveFilter::ParseDomains(const String& domains,
108 String::value_type separator, bool ignoreTrailingDot) const
109 {
110 ParsedDomains parsed = ParseDomainsInternal(domains,
111 separator, ignoreTrailingDot);
112 FillDomains(domains, parsed);
113 }
114
91 void ActiveFilter::AddSitekey(const String& sitekey) const 115 void ActiveFilter::AddSitekey(const String& sitekey) const
92 { 116 {
93 if (!mSitekeys) 117 if (!mSitekeys)
94 { 118 {
95 mSitekeys.reset(new SitekeySet()); 119 mSitekeys.reset(new SitekeySet());
96 annotate_address(mSitekeys.get(), "SitekeySet"); 120 annotate_address(mSitekeys.get(), "SitekeySet");
97 } 121 }
98 122
99 enter_context("Adding to ActiveFilter.mSitekeys"); 123 enter_context("Adding to ActiveFilter.mSitekeys");
100 mSitekeys->insert(sitekey); 124 mSitekeys->insert(sitekey);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 result.append(u'\n'); 210 result.append(u'\n');
187 } 211 }
188 if (mLastHit) 212 if (mLastHit)
189 { 213 {
190 result.append(u"lastHit="_str); 214 result.append(u"lastHit="_str);
191 result.append(mLastHit); 215 result.append(mLastHit);
192 result.append(u'\n'); 216 result.append(u'\n');
193 } 217 }
194 return result; 218 return result;
195 } 219 }
OLDNEW
« no previous file with comments | « compiled/filter/ActiveFilter.h ('k') | compiled/filter/ElemHideBase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld