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-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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 return hostname; | 107 return hostname; |
108 | 108 |
109 return slices[cutoff]; | 109 return slices[cutoff]; |
110 } | 110 } |
111 | 111 |
112 exports.getDomain = getDomain; | 112 exports.getDomain = getDomain; |
113 | 113 |
114 /** | 114 /** |
115 * Checks whether a request's origin is different from its document's origin. | 115 * Checks whether a request's origin is different from its document's origin. |
116 * | 116 * |
117 * @param {URL} url The request URL. | 117 * @param {URL|string} url The request URL. |
Sebastian Noack
2019/02/05 04:32:53
Do we even still need to support the case where an
Manish Jethani
2019/02/05 05:07:28
Actually the default is a URL object now, which is
Sebastian Noack
2019/02/05 05:21:16
So why did you add support for passing in strings
Manish Jethani
2019/02/05 05:42:23
It's there for backwards compatibility with (1) li
Sebastian Noack
2019/02/05 05:54:45
I don't get it, you can just make the unit tsts cr
| |
118 * @param {string} documentHostname The IDNA-encoded hostname of the document. | 118 * @param {string} documentHostname The IDNA-encoded hostname of the document. |
119 * | 119 * |
120 * @returns {boolean} | 120 * @returns {boolean} |
121 */ | 121 */ |
122 function isThirdParty(url, documentHostname) | 122 function isThirdParty(url, documentHostname) |
123 { | 123 { |
124 let requestHostname = url.hostname; | 124 let requestHostname = typeof url == "string" ? new URL(url).hostname : |
125 url.hostname; | |
125 | 126 |
126 if (requestHostname[requestHostname.length - 1] == ".") | 127 if (requestHostname[requestHostname.length - 1] == ".") |
127 requestHostname = requestHostname.replace(/\.+$/, ""); | 128 requestHostname = requestHostname.replace(/\.+$/, ""); |
128 | 129 |
129 if (documentHostname[documentHostname.length - 1] == ".") | 130 if (documentHostname[documentHostname.length - 1] == ".") |
130 documentHostname = documentHostname.replace(/\.+$/, ""); | 131 documentHostname = documentHostname.replace(/\.+$/, ""); |
131 | 132 |
132 if (requestHostname == documentHostname) | 133 if (requestHostname == documentHostname) |
133 return false; | 134 return false; |
134 | 135 |
135 if (!isDomain(requestHostname) || !isDomain(documentHostname)) | 136 if (!isDomain(requestHostname) || !isDomain(documentHostname)) |
136 return true; | 137 return true; |
137 | 138 |
138 return getDomain(requestHostname) != getDomain(documentHostname); | 139 return getDomain(requestHostname) != getDomain(documentHostname); |
139 } | 140 } |
140 | 141 |
141 exports.isThirdParty = isThirdParty; | 142 exports.isThirdParty = isThirdParty; |
OLD | NEW |