Merge pull request #19416 from Snuffleupagus/getFactoryUrlProp
[api-minor] Add more validation for the `cMapUrl`, `standardFontDataUrl`, and `wasmUrl` parameters
This commit is contained in:
commit
90a5c37cb0
@ -258,23 +258,20 @@ function getDocument(src = {}) {
|
|||||||
typeof src.docBaseUrl === "string" && !isDataScheme(src.docBaseUrl)
|
typeof src.docBaseUrl === "string" && !isDataScheme(src.docBaseUrl)
|
||||||
? src.docBaseUrl
|
? src.docBaseUrl
|
||||||
: null;
|
: null;
|
||||||
const cMapUrl = typeof src.cMapUrl === "string" ? src.cMapUrl : null;
|
const cMapUrl = getFactoryUrlProp(src.cMapUrl);
|
||||||
const cMapPacked = src.cMapPacked !== false;
|
const cMapPacked = src.cMapPacked !== false;
|
||||||
const CMapReaderFactory =
|
const CMapReaderFactory =
|
||||||
src.CMapReaderFactory ||
|
src.CMapReaderFactory ||
|
||||||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
||||||
? NodeCMapReaderFactory
|
? NodeCMapReaderFactory
|
||||||
: DOMCMapReaderFactory);
|
: DOMCMapReaderFactory);
|
||||||
const standardFontDataUrl =
|
const standardFontDataUrl = getFactoryUrlProp(src.standardFontDataUrl);
|
||||||
typeof src.standardFontDataUrl === "string"
|
|
||||||
? src.standardFontDataUrl
|
|
||||||
: null;
|
|
||||||
const StandardFontDataFactory =
|
const StandardFontDataFactory =
|
||||||
src.StandardFontDataFactory ||
|
src.StandardFontDataFactory ||
|
||||||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
||||||
? NodeStandardFontDataFactory
|
? NodeStandardFontDataFactory
|
||||||
: DOMStandardFontDataFactory);
|
: DOMStandardFontDataFactory);
|
||||||
const wasmUrl = typeof src.wasmUrl === "string" ? src.wasmUrl : null;
|
const wasmUrl = getFactoryUrlProp(src.wasmUrl);
|
||||||
const WasmFactory =
|
const WasmFactory =
|
||||||
src.WasmFactory ||
|
src.WasmFactory ||
|
||||||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
(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) {
|
function isRefProxy(ref) {
|
||||||
return (
|
return (
|
||||||
typeof ref === "object" &&
|
typeof ref === "object" &&
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user