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-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 * A <code>URLInfo</code> object represents information about a URL. It is | 43 * A <code>URLInfo</code> object represents information about a URL. It is |
44 * returned by <code>{@link parseURL}</code>. | 44 * returned by <code>{@link parseURL}</code>. |
45 */ | 45 */ |
46 class URLInfo | 46 class URLInfo |
47 { | 47 { |
48 /** | 48 /** |
| 49 * Creates a <code>URLInfo</code> object. |
| 50 * |
| 51 * @param {string} href The entire URL. |
| 52 * @param {string} protocol The protocol scheme of the URL, including the |
| 53 * final <code>:</code>. |
| 54 * @param {string} [hostname] The hostname of the URL. |
| 55 * |
49 * @private | 56 * @private |
50 */ | 57 */ |
51 constructor(href, protocol = "", hostname = "") | 58 constructor(href, protocol, hostname = "") |
52 { | 59 { |
53 this._href = href; | 60 this._href = href; |
54 this._protocol = protocol; | 61 this._protocol = protocol; |
55 this._hostname = hostname; | 62 this._hostname = hostname; |
56 } | 63 } |
57 | 64 |
58 /** | 65 /** |
59 * The entire URL. | 66 * The entire URL. |
60 * @type {string} | 67 * @type {string} |
61 */ | 68 */ |
(...skipping 11 matching lines...) Expand all Loading... |
73 return this._protocol; | 80 return this._protocol; |
74 } | 81 } |
75 | 82 |
76 /** | 83 /** |
77 * The hostname of the URL. | 84 * The hostname of the URL. |
78 * @type {string} | 85 * @type {string} |
79 */ | 86 */ |
80 get hostname() | 87 get hostname() |
81 { | 88 { |
82 return this._hostname; | 89 return this._hostname; |
| 90 } |
| 91 |
| 92 /** |
| 93 * Returns the entire URL. |
| 94 * @returns {string} The entire URL. |
| 95 */ |
| 96 toString() |
| 97 { |
| 98 return this._href; |
83 } | 99 } |
84 } | 100 } |
85 | 101 |
86 /** | 102 /** |
87 * Parses a URL to extract the protocol and the hostname. This is a lightweight | 103 * Parses a URL to extract the protocol and the hostname. This is a lightweight |
88 * alternative to the native <code>URL</code> object. Unlike the | 104 * alternative to the native <code>URL</code> object. Unlike the |
89 * <code>URL</code> object, this function is not robust and will give incorrect | 105 * <code>URL</code> object, this function is not robust and will give incorrect |
90 * results for invalid URLs. <em>Use this function with valid, normalized, | 106 * results for invalid URLs. <em>Use this function with valid, normalized, |
91 * properly encoded (IDNA and percent-encoding) URLs only.</em> | 107 * properly encoded (IDNA and percent-encoding) URLs only.</em> |
92 * | 108 * |
93 * @param {string} url The URL to parse. | 109 * @param {string} url The URL to parse. |
94 * @returns {URLInfo} Information about the URL. | 110 * @returns {URLInfo} Information about the URL. |
95 */ | 111 */ |
96 function parseURL(url) | 112 function parseURL(url) |
97 { | 113 { |
98 let match = /^([^:]+:)(?:\/\/(?:[^/]*@)?(\[[^\]]*\]|[^:/]+))?/.exec(url); | 114 let match = /^([^:]+:)(?:\/\/(?:[^/]*@)?(\[[^\]]*\]|[^:/]+))?/.exec(url); |
99 return match ? new URLInfo(url, match[1], match[2]) : new URLInfo(url); | 115 return new URLInfo(url, match[1], match[2]); |
100 } | 116 } |
101 | 117 |
102 exports.parseURL = parseURL; | 118 exports.parseURL = parseURL; |
103 | 119 |
104 /** | 120 /** |
105 * Normalizes a hostname. | 121 * Normalizes a hostname. |
106 * @param {string} hostname | 122 * @param {string} hostname |
107 * @returns {string} | 123 * @returns {string} |
108 */ | 124 */ |
109 function normalizeHostname(hostname) | 125 function normalizeHostname(hostname) |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 if (requestHostname == documentHostname) | 231 if (requestHostname == documentHostname) |
216 return false; | 232 return false; |
217 | 233 |
218 if (!isDomain(requestHostname) || !isDomain(documentHostname)) | 234 if (!isDomain(requestHostname) || !isDomain(documentHostname)) |
219 return true; | 235 return true; |
220 | 236 |
221 return getBaseDomain(requestHostname) != getBaseDomain(documentHostname); | 237 return getBaseDomain(requestHostname) != getBaseDomain(documentHostname); |
222 } | 238 } |
223 | 239 |
224 exports.isThirdParty = isThirdParty; | 240 exports.isThirdParty = isThirdParty; |
LEFT | RIGHT |