diff --git a/dist/HTMLNormalizer/strategies/common.js b/dist/HTMLNormalizer/strategies/common.js index 4bcf054551b512b6c8b66944bf378caeaa458de6..c2869fcc14e30b566074665420047532ba63b86e 100644 --- a/dist/HTMLNormalizer/strategies/common.js +++ b/dist/HTMLNormalizer/strategies/common.js @@ -1,6 +1,7 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cloneAnchorFromPane = exports.pruneElement = exports.amendNodes = exports.ATTRIBUTES_TO_KEEP = exports.ELEMENT_TYPES_TO_REMOVE = void 0; +const url_parse_1 = require("url-parse"); const DUMMY_QR_CODE_ID = "dummyQrCode"; exports.ELEMENT_TYPES_TO_REMOVE = { br: true, @@ -23,10 +24,9 @@ const amendNodes = (document) => { */ const anchors = document.getElementsByTagName("a"); for (const anchor of anchors) { - const url = new URL(anchor.getAttribute("href")); + const url = new url_parse_1.default(anchor.getAttribute("href"), true); if (url.host.includes("safelinks.protection.outlook.com")) { - const originalUrl = new URL(url.searchParams.get("url")); - anchor.setAttribute("href", originalUrl.href); + anchor.setAttribute("href", url.query["url"]); } } }; @@ -53,7 +53,7 @@ const pruneElement = (element) => { exports.pruneElement = pruneElement; const cloneAnchorFromPane = (a, pane) => { try { - const url = new URL(a.getAttribute("href")); + const url = new url_parse_1.default(a.getAttribute("href")); // If this is external url if (url.host && url.protocol) { pane.parentNode.insertBefore(a.cloneNode(false), pane); diff --git a/dist/index.d.ts b/dist/index.d.ts index d964d054d063a199d5a862e1d42194040069438f..9acc7d6b6766c1b1f2ceea8c2959acad9bce8ef4 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,4 +1,3 @@ -import "url-polyfill"; export { default as HTMLNormalizer } from "./HTMLNormalizer"; export { default as PlainNormalizer } from "./PlainNormalizer"; export { EMAIL_VENDORS } from "./constants"; diff --git a/dist/index.js b/dist/index.js index 47124d635031cfdcb16c8cb91109368db7e6e24f..068cf1407a915c35466bfd994ac1cc6d4207d0fb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,7 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EMAIL_VENDORS = exports.PlainNormalizer = exports.HTMLNormalizer = void 0; -require("url-polyfill"); var HTMLNormalizer_1 = require("./HTMLNormalizer"); Object.defineProperty(exports, "HTMLNormalizer", { enumerable: true, get: function () { return HTMLNormalizer_1.default; } }); var PlainNormalizer_1 = require("./PlainNormalizer"); diff --git a/package.json b/package.json index 69b751c566d4c55bc9e39e269507f71a6714c840..8521f459203ff46362026b3a37afe4c58c795f48 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,6 @@ } }, "dependencies": { - "url-polyfill": "^1.1.12" + "url-parse": "^1.4.7" } } diff --git a/src/HTMLNormalizer/strategies/common.ts b/src/HTMLNormalizer/strategies/common.ts index bbf9d15ac3d268430f221c952f12a3e93c6bc4aa..67ae8d2073b9625feeb2c089169b75d1b6633a9f 100644 --- a/src/HTMLNormalizer/strategies/common.ts +++ b/src/HTMLNormalizer/strategies/common.ts @@ -1,3 +1,5 @@ +import URL from "url-parse"; + const DUMMY_QR_CODE_ID = "dummyQrCode"; export const ELEMENT_TYPES_TO_REMOVE = { @@ -23,11 +25,10 @@ export const amendNodes = (document: HTMLDocument): void => { */ const anchors = document.getElementsByTagName("a"); for (const anchor of anchors) { - const url = new URL(anchor.getAttribute("href")); + const url = new URL(anchor.getAttribute("href"), true); if (url.host.includes("safelinks.protection.outlook.com")) { - const originalUrl = new URL(url.searchParams.get("url")); - anchor.setAttribute("href", originalUrl.href); + anchor.setAttribute("href", url.query["url"]); } } }; diff --git a/src/index.ts b/src/index.ts index 70e168e2a04f99973fa794afbd5300a174510c07..00810e4212481f083bbf524efedab1ace2938abf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,3 @@ -import "url-polyfill"; - export { default as HTMLNormalizer } from "./HTMLNormalizer"; export { default as PlainNormalizer } from "./PlainNormalizer"; diff --git a/yarn.lock b/yarn.lock index 1ab69fddc8cba1ed9e5d8ec47ff8e400bf76f36f..7735452501a1bf4dcfbaefe3995b606d823419ad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4010,6 +4010,11 @@ qs@~6.5.2: resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA== +querystringify@^2.1.1: + version "2.2.0" + resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.2.0.tgz#3345941b4153cb9d082d8eee4cda2016a9aef7f6" + integrity sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ== + react-is@^17.0.1: version "17.0.1" resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.1.tgz#5b3531bd76a645a4c9fb6e693ed36419e3301339" @@ -4162,6 +4167,11 @@ require-main-filename@^2.0.0: resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg== +requires-port@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" + integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8= + resolve-cwd@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-3.0.0.tgz#0f0075f1bb2544766cf73ba6a6e2adfebcb13f2d" @@ -4865,10 +4875,13 @@ urix@^0.1.0: resolved "https://registry.yarnpkg.com/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72" integrity sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI= -url-polyfill@^1.1.12: - version "1.1.12" - resolved "https://registry.yarnpkg.com/url-polyfill/-/url-polyfill-1.1.12.tgz#6cdaa17f6b022841b3aec0bf8dbd87ac0cd33331" - integrity sha512-mYFmBHCapZjtcNHW0MDq9967t+z4Dmg5CJ0KqysK3+ZbyoNOWQHksGCTWwDhxGXllkWlOc10Xfko6v4a3ucM6A== +url-parse@^1.4.7: + version "1.4.7" + resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.4.7.tgz#a8a83535e8c00a316e403a5db4ac1b9b853ae278" + integrity sha512-d3uaVyzDB9tQoSXFvuSUNFibTd9zxd2bkVrDRvF5TmvWWQwqE4lgYJ5m+x1DbecWkw+LK4RNl2CU1hHuOKPVlg== + dependencies: + querystringify "^2.1.1" + requires-port "^1.0.0" use@^3.1.0: version "3.1.1"