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.
This commit is contained in:
parent
9190445a21
commit
c5ee72bb95
@ -16,7 +16,7 @@
|
|||||||
/** @typedef {import("./event_utils").EventBus} EventBus */
|
/** @typedef {import("./event_utils").EventBus} EventBus */
|
||||||
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
|
/** @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";
|
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.');
|
throw new Error('A valid "url" parameter must provided.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const urlNullRemoved = removeNullCharacters(url);
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
link.href = link.title = urlNullRemoved;
|
link.href = link.title = url;
|
||||||
} else {
|
} else {
|
||||||
link.href = "";
|
link.href = "";
|
||||||
link.title = `Disabled: ${urlNullRemoved}`;
|
link.title = `Disabled: ${url}`;
|
||||||
link.onclick = () => {
|
link.onclick = () => {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user