 Issue 29336787:
  Issue 3670 - Make rules case sensitive where possible  (Closed)
    
  
    Issue 29336787:
  Issue 3670 - Make rules case sensitive where possible  (Closed) 
  | Left: | ||
| Right: | 
| OLD | NEW | 
|---|---|
| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 { | 165 { | 
| 166 result.push(domain); | 166 result.push(domain); | 
| 167 | 167 | 
| 168 if (getBaseDomain(domain) == domain) | 168 if (getBaseDomain(domain) == domain) | 
| 169 result.push("www." + domain); | 169 result.push("www." + domain); | 
| 170 } | 170 } | 
| 171 | 171 | 
| 172 return result; | 172 return result; | 
| 173 } | 173 } | 
| 174 | 174 | 
| 175 function caseSensitive(filter) | |
| 
Sebastian Noack
2016/02/21 21:42:30
It probably makes sense to integrate the logic her
 
kzar
2016/02/24 15:43:29
Done.
 | |
| 176 { | |
| 177 if (filter.matchCase) | |
| 178 return true; | |
| 179 | |
| 180 if (!(filter.text.startsWith("||") || filter.text.startsWith("://"))) | |
| 
Sebastian Noack
2016/02/21 21:42:30
Filters usually don't start with "://". But filter
 
kzar
2016/02/24 15:43:29
Done.
 | |
| 181 return false; | |
| 182 | |
| 183 let offset = filter.text.startsWith("||") ? 2 : 3; | |
| 184 let boundary = filter.text.substr(offset).search(/\/\?\*\^/); | |
| 
Sebastian Noack
2016/02/21 21:42:30
This regular expression would only match a seqeunc
 
kzar
2016/02/24 15:43:29
(Yep, forgot the brackets.)
 | |
| 185 | |
| 186 if (boundary == -1) | |
| 187 return true; | |
| 188 | |
| 189 return filter.text.substr(offset + boundary + 1).search(/[a-zA-Z]/) == -1; | |
| 190 } | |
| 191 | |
| 175 function convertFilter(filter, action, withResourceTypes) | 192 function convertFilter(filter, action, withResourceTypes) | 
| 176 { | 193 { | 
| 177 let trigger = {"url-filter": getRegExpSource(filter)}; | 194 let trigger = {"url-filter": getRegExpSource(filter)}; | 
| 178 let included = []; | 195 let included = []; | 
| 179 let excluded = []; | 196 let excluded = []; | 
| 180 | 197 | 
| 198 if (caseSensitive(filter)) | |
| 199 trigger["url-filter-is-case-sensitive"] = true; | |
| 200 | |
| 181 parseDomains(filter.domains, included, excluded); | 201 parseDomains(filter.domains, included, excluded); | 
| 182 | 202 | 
| 183 if (withResourceTypes) | 203 if (withResourceTypes) | 
| 184 trigger["resource-type"] = getResourceTypes(filter); | 204 trigger["resource-type"] = getResourceTypes(filter); | 
| 185 if (filter.thirdParty != null) | 205 if (filter.thirdParty != null) | 
| 186 trigger["load-type"] = [filter.thirdParty ? "third-party" : "first-party"]; | 206 trigger["load-type"] = [filter.thirdParty ? "third-party" : "first-party"]; | 
| 187 | 207 | 
| 188 if (included.length > 0) | 208 if (included.length > 0) | 
| 189 trigger["if-domain"] = addDomainPrefix(included); | 209 trigger["if-domain"] = addDomainPrefix(included); | 
| 190 else if (excluded.length > 0) | 210 else if (excluded.length > 0) | 
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 { | 375 { | 
| 356 while (selectors.length) | 376 while (selectors.length) | 
| 357 { | 377 { | 
| 358 let selector = selectors.splice(0, selectorLimit).join(", "); | 378 let selector = selectors.splice(0, selectorLimit).join(", "); | 
| 359 | 379 | 
| 360 // As of Safari 9.0 element IDs are matched as lowercase. We work around | 380 // As of Safari 9.0 element IDs are matched as lowercase. We work around | 
| 361 // this by converting to the attribute format [id="elementID"] | 381 // this by converting to the attribute format [id="elementID"] | 
| 362 selector = convertIDSelectorsToAttributeSelectors(selector); | 382 selector = convertIDSelectorsToAttributeSelectors(selector); | 
| 363 | 383 | 
| 364 addRule({ | 384 addRule({ | 
| 365 trigger: {"url-filter": matchDomain}, | 385 trigger: {"url-filter": matchDomain, | 
| 
Sebastian Noack
2016/02/21 21:42:30
Same for element hiding filters; we have to make s
 
kzar
2016/02/24 15:43:29
Done.
 | |
| 386 "url-filter-is-case-sensitive": true}, | |
| 366 action: {type: "css-display-none", | 387 action: {type: "css-display-none", | 
| 367 selector: selector} | 388 selector: selector} | 
| 368 }); | 389 }); | 
| 369 } | 390 } | 
| 370 }); | 391 }); | 
| 371 | 392 | 
| 372 for (let filter of elemhideExceptions) | 393 for (let filter of elemhideExceptions) | 
| 373 addRule(convertFilter(filter, "ignore-previous-rules", false)); | 394 addRule(convertFilter(filter, "ignore-previous-rules", false)); | 
| 374 for (let filter of requestFilters) | 395 for (let filter of requestFilters) | 
| 375 addRule(convertFilter(filter, "block", true)); | 396 addRule(convertFilter(filter, "block", true)); | 
| 376 for (let filter of requestExceptions) | 397 for (let filter of requestExceptions) | 
| 377 addRule(convertFilter(filter, "ignore-previous-rules", true)); | 398 addRule(convertFilter(filter, "ignore-previous-rules", true)); | 
| 378 | 399 | 
| 379 return rules; | 400 return rules; | 
| 380 }; | 401 }; | 
| OLD | NEW |