1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-23 08:38:06 +02:00

[api-minor] Add more validation for the cMapUrl, standardFontDataUrl, and wasmUrl parameters

Given that we now have a few different factory-url parameters, we introduce a helper function for parsing them.

*Please note:* These parameters have always been documented as requiring a trailing slash[1], which we can now easily enforce during the `getDocument`-call.

---
[1] I recall that we've occasionally seen issues because users miss that detail, and the new Error should hopefully be more easily actionable than one thrown during rendering/parsing.
This commit is contained in:
Jonas Jenwald 2025-02-04 10:27:31 +01:00
parent d1f62509e5
commit fa3358baf9

View file

@ -258,23 +258,20 @@ function getDocument(src = {}) {
typeof src.docBaseUrl === "string" && !isDataScheme(src.docBaseUrl)
? src.docBaseUrl
: null;
const cMapUrl = typeof src.cMapUrl === "string" ? src.cMapUrl : null;
const cMapUrl = getFactoryUrlProp(src.cMapUrl);
const cMapPacked = src.cMapPacked !== false;
const CMapReaderFactory =
src.CMapReaderFactory ||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
? NodeCMapReaderFactory
: DOMCMapReaderFactory);
const standardFontDataUrl =
typeof src.standardFontDataUrl === "string"
? src.standardFontDataUrl
: null;
const standardFontDataUrl = getFactoryUrlProp(src.standardFontDataUrl);
const StandardFontDataFactory =
src.StandardFontDataFactory ||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
? NodeStandardFontDataFactory
: DOMStandardFontDataFactory);
const wasmUrl = typeof src.wasmUrl === "string" ? src.wasmUrl : null;
const wasmUrl = getFactoryUrlProp(src.wasmUrl);
const WasmFactory =
src.WasmFactory ||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
@ -580,6 +577,16 @@ function getDataProp(val) {
);
}
function getFactoryUrlProp(val) {
if (typeof val !== "string") {
return null;
}
if (val.endsWith("/")) {
return val;
}
throw new Error(`Invalid factory url: "${val}" must include trailing slash.`);
}
function isRefProxy(ref) {
return (
typeof ref === "object" &&