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 14 matching lines...) Expand all Loading... |
25 let getDecodedHostname = | 25 let getDecodedHostname = |
26 /** | 26 /** |
27 * Gets the IDN-decoded hostname from a URL object. | 27 * Gets the IDN-decoded hostname from a URL object. |
28 * | 28 * |
29 * @param {URL} url | 29 * @param {URL} url |
30 * @return {string} | 30 * @return {string} |
31 * @static | 31 * @static |
32 */ | 32 */ |
33 exports.getDecodedHostname = url => | 33 exports.getDecodedHostname = url => |
34 { | 34 { |
35 let hostname = url.hostname; | 35 let {hostname} = url; |
36 | 36 |
37 if (hostname.indexOf("xn--") == -1) | 37 if (hostname.indexOf("xn--") == -1) |
38 return hostname; | 38 return hostname; |
39 | 39 |
40 return punycode.toUnicode(hostname); | 40 return punycode.toUnicode(hostname); |
41 }; | 41 }; |
42 | 42 |
43 /** | 43 /** |
44 * Gets the IDN-decoded hostname from the URL of a frame. | 44 * Gets the IDN-decoded hostname from the URL of a frame. |
45 * If the URL don't have host information (like "about:blank" | 45 * If the URL don't have host information (like "about:blank" |
(...skipping 16 matching lines...) Expand all Loading... |
62 | 62 |
63 /** | 63 /** |
64 * Converts a URL object into a string. For HTTP(S) URLs | 64 * Converts a URL object into a string. For HTTP(S) URLs |
65 * the hostname gets IDN-decoded and the hash is stripped. | 65 * the hostname gets IDN-decoded and the hash is stripped. |
66 * | 66 * |
67 * @param {URL} url | 67 * @param {URL} url |
68 * @return {string} | 68 * @return {string} |
69 */ | 69 */ |
70 exports.stringifyURL = url => | 70 exports.stringifyURL = url => |
71 { | 71 { |
72 let protocol = url.protocol; | 72 let {protocol, href} = url; |
73 let href = url.href; | |
74 | 73 |
75 if (protocol == "http:" || protocol == "https:") | 74 if (protocol == "http:" || protocol == "https:") |
76 { | 75 { |
77 let hostname = url.hostname; | 76 let {hostname} = url; |
78 if (hostname.indexOf("xn--") != -1) | 77 if (hostname.indexOf("xn--") != -1) |
79 href = href.replace(hostname, punycode.toUnicode(hostname)); | 78 href = href.replace(hostname, punycode.toUnicode(hostname)); |
80 | 79 |
81 let hash = href.indexOf("#"); | 80 let hash = href.indexOf("#"); |
82 if (hash != -1) | 81 if (hash != -1) |
83 href = href.substr(0, hash); | 82 href = href.substr(0, hash); |
84 } | 83 } |
85 | 84 |
86 return href; | 85 return href; |
87 }; | 86 }; |
(...skipping 22 matching lines...) Expand all Loading... |
110 documentHost = documentHost.replace(/\.+$/, ""); | 109 documentHost = documentHost.replace(/\.+$/, ""); |
111 | 110 |
112 if (requestHost == documentHost) | 111 if (requestHost == documentHost) |
113 return false; | 112 return false; |
114 | 113 |
115 if (!isDomain(requestHost) || !isDomain(documentHost)) | 114 if (!isDomain(requestHost) || !isDomain(documentHost)) |
116 return true; | 115 return true; |
117 | 116 |
118 return getDomain(requestHost) != getDomain(documentHost); | 117 return getDomain(requestHost) != getDomain(documentHost); |
119 }; | 118 }; |
OLD | NEW |