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-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 28 matching lines...) Expand all Loading... |
39 return map; | 39 return map; |
40 } | 40 } |
41 | 41 |
42 /** | 42 /** |
43 * Yields all suffixes for a domain. For example, given the domain | 43 * Yields all suffixes for a domain. For example, given the domain |
44 * <code>www.example.com</code>, this function yields | 44 * <code>www.example.com</code>, this function yields |
45 * <code>www.example.com</code>, <code>example.com</code>, and | 45 * <code>www.example.com</code>, <code>example.com</code>, and |
46 * <code>com</code>, in that order. | 46 * <code>com</code>, in that order. |
47 * | 47 * |
48 * @param {string} domain The domain. | 48 * @param {string} domain The domain. |
| 49 * @param {boolean} [includeBlank] Whether to include the blank suffix at the |
| 50 * end. |
| 51 * |
49 * @yields {string} The next suffix for the domain. | 52 * @yields {string} The next suffix for the domain. |
50 */ | 53 */ |
51 function* suffixes(domain) | 54 function* suffixes(domain, includeBlank = false) |
52 { | 55 { |
53 while (domain != "") | 56 while (domain != "") |
54 { | 57 { |
55 yield domain; | 58 yield domain; |
56 | 59 |
57 let dotIndex = domain.indexOf("."); | 60 let dotIndex = domain.indexOf("."); |
58 domain = dotIndex == -1 ? "" : domain.substr(dotIndex + 1); | 61 domain = dotIndex == -1 ? "" : domain.substr(dotIndex + 1); |
59 } | 62 } |
| 63 |
| 64 if (includeBlank) |
| 65 yield ""; |
60 } | 66 } |
61 | 67 |
| 68 exports.suffixes = suffixes; |
| 69 |
62 /** | 70 /** |
63 * Checks whether the given hostname is a domain. | 71 * Checks whether the given hostname is a domain. |
64 * | 72 * |
65 * @param {string} hostname | 73 * @param {string} hostname |
66 * @returns {boolean} | 74 * @returns {boolean} |
67 */ | 75 */ |
68 function isDomain(hostname) | 76 function isDomain(hostname) |
69 { | 77 { |
70 // No hostname or IPv4 address, also considering hexadecimal octets. | 78 // No hostname or IPv4 address, also considering hexadecimal octets. |
71 if (/^((0x[\da-f]+|\d+)(\.|$))*$/i.test(hostname)) | 79 if (/^((0x[\da-f]+|\d+)(\.|$))*$/i.test(hostname)) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 if (requestHostname == documentHostname) | 140 if (requestHostname == documentHostname) |
133 return false; | 141 return false; |
134 | 142 |
135 if (!isDomain(requestHostname) || !isDomain(documentHostname)) | 143 if (!isDomain(requestHostname) || !isDomain(documentHostname)) |
136 return true; | 144 return true; |
137 | 145 |
138 return getDomain(requestHostname) != getDomain(documentHostname); | 146 return getDomain(requestHostname) != getDomain(documentHostname); |
139 } | 147 } |
140 | 148 |
141 exports.isThirdParty = isThirdParty; | 149 exports.isThirdParty = isThirdParty; |
OLD | NEW |