| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 let canSafelyMatchAsLowercase = false; | 85 let canSafelyMatchAsLowercase = false; |
| 86 | 86 |
| 87 for (let i = 0; i < text.length; i++) | 87 for (let i = 0; i < text.length; i++) |
| 88 { | 88 { |
| 89 let c = text[i]; | 89 let c = text[i]; |
| 90 | 90 |
| 91 // If we're currently inside the hostname we have to be careful not to | 91 // If we're currently inside the hostname we have to be careful not to |
| 92 // escape any characters until after we have converted it to punycode. | 92 // escape any characters until after we have converted it to punycode. |
| 93 if (hostnameStart != null && !hostnameFinished) | 93 if (hostnameStart != null && !hostnameFinished) |
| 94 { | 94 { |
| 95 if (c == "*" || c == "^" || c == "?" || c == "/" || i == lastIndex) | 95 let endingChar = (c == "*" || c == "^" || |
|
Sebastian Noack
2016/02/27 20:30:38
If you turn the logic here the other way around, y
Sebastian Noack
2016/02/27 20:30:38
I'm not entirely sure if the case of last index is
kzar
2016/02/27 21:28:53
Done.
kzar
2016/02/27 21:28:53
Good point but it's even more complicated, what if
| |
| 96 { | 96 c == "?" || c == "/" || c == "|"); |
| 97 hostnameFinished = true; | 97 if (!endingChar && i != lastIndex) |
| 98 let hostname = text.substring(hostnameStart, i); | |
| 99 result.push(escapeRegExp(punycode.toASCII(hostname))); | |
| 100 } | |
| 101 else | |
| 102 continue; | 98 continue; |
| 99 | |
| 100 let hostname = text.substring(hostnameStart, endingChar ? i : i + 1); | |
| 101 hostnameFinished = true; | |
| 102 result.push(escapeRegExp(punycode.toASCII(hostname))); | |
| 103 if (!endingChar) | |
| 104 break; | |
| 103 } | 105 } |
| 104 | 106 |
| 105 switch (c) | 107 switch (c) |
| 106 { | 108 { |
| 107 case "*": | 109 case "*": |
| 108 if (result.length > 0 && i < lastIndex && text[i + 1] != "*") | 110 if (result.length > 0 && i < lastIndex && text[i + 1] != "*") |
| 109 result.push(".*"); | 111 result.push(".*"); |
| 110 break; | 112 break; |
| 111 case "^": | 113 case "^": |
| 112 if (i < lastIndex) | 114 if (i < lastIndex) |
| 113 result.push("."); | 115 result.push("."); |
| 114 break; | 116 break; |
| 115 case "|": | 117 case "|": |
| 116 if (i == 0) | 118 if (i == 0) |
| 117 { | 119 { |
| 118 result.push("^"); | 120 result.push("^"); |
| 119 break; | 121 break; |
| 120 } | 122 } |
| 121 if (i == lastIndex) | 123 if (i == lastIndex) |
| 122 { | 124 { |
| 123 result.push("$"); | 125 result.push("$"); |
| 124 break; | 126 break; |
| 125 } | 127 } |
| 126 if (i == 1 && text[0] == "|") | 128 if (i == 1 && text[0] == "|") |
| 127 { | 129 { |
| 128 result.push("https?://"); | |
| 129 hostnameStart = i + 1; | 130 hostnameStart = i + 1; |
| 130 canSafelyMatchAsLowercase = true; | 131 canSafelyMatchAsLowercase = true; |
| 132 result.push("https?://"); | |
| 131 break; | 133 break; |
| 132 } | 134 } |
| 133 result.push("\\|"); | 135 result.push("\\|"); |
| 134 break; | 136 break; |
| 135 case "/": | 137 case "/": |
| 136 result.push("/"); | |
|
Sebastian Noack
2016/02/27 20:30:38
Nit: Mind moving that line to just above the break
kzar
2016/02/27 21:28:53
Done.
| |
| 137 if (!hostnameFinished && | 138 if (!hostnameFinished && |
|
Sebastian Noack
2016/02/27 20:30:38
Nit: It doesn't matter, but I personally find that
kzar
2016/02/27 21:28:53
I'd rather leave this one as it is.
| |
| 138 text.charAt(i-2) == ":" && text.charAt(i-1) == "/") | 139 text.charAt(i-2) == ":" && text.charAt(i-1) == "/") |
| 139 { | 140 { |
| 140 hostnameStart = i + 1; | 141 hostnameStart = i + 1; |
| 141 canSafelyMatchAsLowercase = true; | 142 canSafelyMatchAsLowercase = true; |
| 142 } | 143 } |
| 143 break; | 144 result.push("/"); |
| 144 case ".": case "+": case "$": case "{": case "}": case "?": | 145 break; |
|
Sebastian Noack
2016/02/27 20:30:38
Nit: I think the way this block was originally wra
kzar
2016/02/27 21:28:53
Done.
| |
| 145 case "(": case ")": case "[": case "]": case "\\": | 146 case ".": case "+": case "$": case "?": |
| 147 case "{": case "}": case "(": case ")": | |
| 148 case "[": case "]": case "\\": | |
| 146 result.push("\\", c); | 149 result.push("\\", c); |
| 147 break; | 150 break; |
| 148 default: | 151 default: |
| 149 if (hostnameFinished && (c >= "a" && c <= "z" || | 152 if (hostnameFinished && (c >= "a" && c <= "z" || |
| 150 c >= "A" && c <= "Z")) | 153 c >= "A" && c <= "Z")) |
| 151 canSafelyMatchAsLowercase = false; | 154 canSafelyMatchAsLowercase = false; |
| 152 result.push(c); | 155 result.push(c); |
| 153 } | 156 } |
| 154 } | 157 } |
| 155 | 158 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 | 437 |
| 435 for (let filter of this.elemhideExceptions) | 438 for (let filter of this.elemhideExceptions) |
| 436 addRule(convertFilter(filter, "ignore-previous-rules", false)); | 439 addRule(convertFilter(filter, "ignore-previous-rules", false)); |
| 437 for (let filter of this.requestFilters) | 440 for (let filter of this.requestFilters) |
| 438 addRule(convertFilter(filter, "block", true)); | 441 addRule(convertFilter(filter, "block", true)); |
| 439 for (let filter of this.requestExceptions) | 442 for (let filter of this.requestExceptions) |
| 440 addRule(convertFilter(filter, "ignore-previous-rules", true)); | 443 addRule(convertFilter(filter, "ignore-previous-rules", true)); |
| 441 | 444 |
| 442 return rules; | 445 return rules; |
| 443 }; | 446 }; |
| LEFT | RIGHT |