From c5ee72bb950e97bcb7362399f942baab94c2b89b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 31 Aug 2023 18:52:07 +0200 Subject: [PATCH] Stop using `removeNullCharacters` in the `addLinkAttributes` helper function Using `removeNullCharacters` on the URL should be completely redundant, given the kind of data that we're passing to the `addLinkAttributes` helper function. Note that whenever we're handling a URL, originating in the worker-thread, in the viewer that helper function is always being used. Furthermore, on the worker-thread all URLs are parsed with the `createValidAbsoluteUrl` helper function, which uses `new URL()` to ensure that a valid URL is obtained. Note that the `URL` constructor will either throw, or in some cases just ignore them, when encountering `\u0000`-characters during parsing. Hence it should be *impossible* for a valid URL to contain `\u0000`-characters and we can thus simplify the viewer-code a tiny bit. The use of `removeNullCharacters` is most likely a left-over from back when `new URL()` wasn't generally available in browsers. --- web/pdf_link_service.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/web/pdf_link_service.js b/web/pdf_link_service.js index 3b5935a04..b2361f7cf 100644 --- a/web/pdf_link_service.js +++ b/web/pdf_link_service.js @@ -16,7 +16,7 @@ /** @typedef {import("./event_utils").EventBus} EventBus */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ -import { parseQueryString, removeNullCharacters } from "./ui_utils.js"; +import { parseQueryString } from "./ui_utils.js"; const DEFAULT_LINK_REL = "noopener noreferrer nofollow"; @@ -49,12 +49,11 @@ function addLinkAttributes(link, { url, target, rel, enabled = true } = {}) { throw new Error('A valid "url" parameter must provided.'); } - const urlNullRemoved = removeNullCharacters(url); if (enabled) { - link.href = link.title = urlNullRemoved; + link.href = link.title = url; } else { link.href = ""; - link.title = `Disabled: ${urlNullRemoved}`; + link.title = `Disabled: ${url}`; link.onclick = () => { return false; };