mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-28 23:28:16 +02:00
[api-minor] Move the addDefaultProtocolToUrl
/tryConvertUrlEncoding
functionality into the createValidAbsoluteUrl
function
Having recently worked with, and reviewed patches touching, this code it seemed that it's probably not a bad idea to move that functionality into `createValidAbsoluteUrl` as new options instead. For the `addDefaultProtocolToUrl` functionality in particular, the existing helper function was not only moved but slightly improved as well. Looking at the code, I realized that there's a small risk that it would incorrectly match a *relative* URL-string too. With these changes, the `createValidAbsoluteUrl` call-sites in the `src/core/`-code can be simplified a little bit. *Please note:* This patch may, indirectly, change the format of the `unsafeUrl`-property returned with relevant Annotations and OutlineItems; hence the `api-minor` tag. However, I'd argue that it's actually more correct this way since the whole purpose of `unsafeUrl` is/was to return the URL data as-is without any parsing done.
This commit is contained in:
parent
3b3c487bed
commit
e6e04694f4
5 changed files with 42 additions and 48 deletions
|
@ -26,10 +26,6 @@ import {
|
|||
$toStyle,
|
||||
XFAObject,
|
||||
} from "./xfa_object.js";
|
||||
import {
|
||||
addDefaultProtocolToUrl,
|
||||
tryConvertUrlEncoding,
|
||||
} from "../core_utils.js";
|
||||
import { createValidAbsoluteUrl, warn } from "../../shared/util.js";
|
||||
import { getMeasurement, stripQuotes } from "./utils.js";
|
||||
import { selectFont } from "./fonts.js";
|
||||
|
@ -638,15 +634,11 @@ function setFontFamily(xfaFont, node, fontFinder, style) {
|
|||
}
|
||||
|
||||
function fixURL(str) {
|
||||
if (typeof str === "string") {
|
||||
let url = addDefaultProtocolToUrl(str);
|
||||
url = tryConvertUrlEncoding(url);
|
||||
const absoluteUrl = createValidAbsoluteUrl(url);
|
||||
if (absoluteUrl) {
|
||||
return absoluteUrl.href;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
const absoluteUrl = createValidAbsoluteUrl(str, /* baseUrl = */ null, {
|
||||
addDefaultProtocol: true,
|
||||
tryConvertEncoding: true,
|
||||
});
|
||||
return absoluteUrl ? absoluteUrl.href : null;
|
||||
}
|
||||
|
||||
export {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue