mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
Merge pull request #19493 from Snuffleupagus/URL-parse
Introduce some `URL.parse()` usage in the code-base
This commit is contained in:
commit
e3ea92603d
5 changed files with 52 additions and 72 deletions
39
web/app.js
39
web/app.js
|
@ -2274,35 +2274,34 @@ if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
|||
}
|
||||
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
const HOSTED_VIEWER_ORIGINS = [
|
||||
const HOSTED_VIEWER_ORIGINS = new Set([
|
||||
"null",
|
||||
"http://mozilla.github.io",
|
||||
"https://mozilla.github.io",
|
||||
];
|
||||
]);
|
||||
// eslint-disable-next-line no-var
|
||||
var validateFileURL = function (file) {
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const viewerOrigin = new URL(window.location.href).origin || "null";
|
||||
if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
|
||||
// Hosted or local viewer, allow for any file locations
|
||||
return;
|
||||
}
|
||||
const fileOrigin = new URL(file, window.location.href).origin;
|
||||
// Removing of the following line will not guarantee that the viewer will
|
||||
// start accepting URLs from foreign origin -- CORS headers on the remote
|
||||
// server must be properly configured.
|
||||
if (fileOrigin !== viewerOrigin) {
|
||||
throw new Error("file origin does not match viewer's");
|
||||
}
|
||||
} catch (ex) {
|
||||
PDFViewerApplication._documentError("pdfjs-loading-error", {
|
||||
message: ex.message,
|
||||
});
|
||||
throw ex;
|
||||
const viewerOrigin = URL.parse(window.location)?.origin || "null";
|
||||
if (HOSTED_VIEWER_ORIGINS.has(viewerOrigin)) {
|
||||
// Hosted or local viewer, allow for any file locations
|
||||
return;
|
||||
}
|
||||
const fileOrigin = URL.parse(file, window.location)?.origin;
|
||||
if (fileOrigin === viewerOrigin) {
|
||||
return;
|
||||
}
|
||||
const ex = new Error("file origin does not match viewer's");
|
||||
|
||||
PDFViewerApplication._documentError("pdfjs-loading-error", {
|
||||
message: ex.message,
|
||||
});
|
||||
// Removing of the following line will not guarantee that the viewer will
|
||||
// start accepting URLs from foreign origin -- CORS headers on the remote
|
||||
// server must be properly configured.
|
||||
throw ex;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line no-var
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue