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

Side by Side Diff: lib/abp2blocklist.js

Issue 29467595: Issue 5325 - Add support for separator characters (Closed) Base URL: https://hg.adblockplus.org/abp2blocklist
Patch Set: Add comment about using only lower case for hostname Created July 11, 2017, 5: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 | « no previous file | test/abp2blocklist.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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 break; 141 break;
142 } 142 }
143 143
144 switch (c) 144 switch (c)
145 { 145 {
146 case "*": 146 case "*":
147 if (regexp.length > 0 && i < lastIndex && text[i + 1] != "*") 147 if (regexp.length > 0 && i < lastIndex && text[i + 1] != "*")
148 regexp.push(".*"); 148 regexp.push(".*");
149 break; 149 break;
150 case "^": 150 case "^":
151 if (i < lastIndex) 151 let alphabet = "a-z";
152 regexp.push("."); 152 // If justHostname is true and we've encountered a "^", it means we're
153 // still in the hostname part of the URL. Since hostnames are always
154 // lower case (Punycode), there's no need to include "A-Z" in the
155 // pattern. Further, subsequent code may lower-case the entire regular
156 // expression (if the URL contains only the hostname part), leaving us
157 // with "a-za-z", which would be redundant.
158 if (!justHostname)
159 alphabet = "A-Z" + alphabet;
160 let digits = "0-9";
161 // Note that the "-" must appear first here in order to retain its
162 // literal meaning within the brackets.
163 let specialCharacters = "-_.%";
164 let separator = "[^" + specialCharacters + alphabet + digits + "]";
165 if (i == 0)
166 regexp.push("^https?://(.*" + separator + ")?");
167 else if (i == lastIndex)
168 regexp.push("(" + separator + ".*)?$");
169 else
170 regexp.push(separator);
153 break; 171 break;
154 case "|": 172 case "|":
155 if (i == 0) 173 if (i == 0)
156 { 174 {
157 regexp.push("^"); 175 regexp.push("^");
158 break; 176 break;
159 } 177 }
160 if (i == lastIndex) 178 if (i == lastIndex)
161 { 179 {
162 regexp.push("$"); 180 regexp.push("$");
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 { 557 {
540 convertFilterAddRules(rules, filter, "block", true, 558 convertFilterAddRules(rules, filter, "block", true,
541 requestFilterExceptionDomains); 559 requestFilterExceptionDomains);
542 } 560 }
543 561
544 for (let filter of this.requestExceptions) 562 for (let filter of this.requestExceptions)
545 convertFilterAddRules(rules, filter, "ignore-previous-rules", true); 563 convertFilterAddRules(rules, filter, "ignore-previous-rules", true);
546 564
547 return rules.filter(rule => !hasNonASCI(rule)); 565 return rules.filter(rule => !hasNonASCI(rule));
548 }; 566 };
OLDNEW
« no previous file with comments | « no previous file | test/abp2blocklist.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld