Skip to content

Commit

Permalink
Merge pull request #19416 from Snuffleupagus/getFactoryUrlProp
Browse files Browse the repository at this point in the history
[api-minor] Add more validation for the `cMapUrl`, `standardFontDataUrl`, and `wasmUrl` parameters
  • Loading branch information
Snuffleupagus authored Feb 4, 2025
2 parents 212388a + fa3358b commit 90a5c37
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" &&
Expand Down

0 comments on commit 90a5c37

Please sign in to comment.