| Index: lib/url.js |
| =================================================================== |
| --- a/lib/url.js |
| +++ b/lib/url.js |
| @@ -12,30 +12,27 @@ |
| * GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License |
| * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| */ |
| /** @module url */ |
| -"use strict"; |
| +import {getDomain} from "tldjs"; |
| +import punycode from "punycode"; |
| -const {getDomain} = require("tldjs"); |
| -const punycode = require("punycode"); |
| - |
| -let getDecodedHostname = |
| /** |
| * Gets the IDN-decoded hostname from a URL object. |
| * |
| * @param {URL} url |
| * @return {string} |
| * @static |
| */ |
| -exports.getDecodedHostname = url => |
| +export const getDecodedHostname = url => |
| { |
| let {hostname} = url; |
| if (hostname.indexOf("xn--") == -1) |
| return hostname; |
| return punycode.toUnicode(hostname); |
| }; |
| @@ -43,17 +40,17 @@ |
| /** |
| * Gets the IDN-decoded hostname from the URL of a frame. |
| * If the URL don't have host information (like "about:blank" |
| * and "data:" URLs) it falls back to the parent frame. |
| * |
| * @param {Frame} frame |
| * @return {string} |
| */ |
| -exports.extractHostFromFrame = frame => |
| +export const extractHostFromFrame = frame => |
| { |
| for (; frame; frame = frame.parent) |
| { |
| let hostname = getDecodedHostname(frame.url); |
| if (hostname) |
| return hostname; |
| } |
| @@ -62,17 +59,17 @@ |
| /** |
| * Converts a URL object into a string. For HTTP(S) URLs |
| * the hostname gets IDN-decoded and the hash is stripped. |
| * |
| * @param {URL} url |
| * @return {string} |
| */ |
| -exports.stringifyURL = url => |
| +export const stringifyURL = url => |
| { |
| let {protocol, href} = url; |
| if (protocol == "http:" || protocol == "https:") |
| { |
| let {hostname} = url; |
| if (hostname.indexOf("xn--") != -1) |
| href = href.replace(hostname, punycode.toUnicode(hostname)); |
| @@ -98,17 +95,17 @@ |
| /** |
| * Checks whether the request's origin is different from the document's origin. |
| * |
| * @param {URL} url The request URL |
| * @param {string} documentHost The IDN-decoded hostname of the document |
| * @return {Boolean} |
| */ |
| -exports.isThirdParty = (url, documentHost) => |
| +export const isThirdParty = (url, documentHost) => |
| { |
| let requestHost = getDecodedHostname(url).replace(/\.+$/, ""); |
| documentHost = documentHost.replace(/\.+$/, ""); |
| if (requestHost == documentHost) |
| return false; |
| if (!isDomain(requestHost) || !isDomain(documentHost)) |