1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-24 09:08:07 +02:00

Merge pull request #14656 from Snuffleupagus/mv-isSameOrigin

Move the `isSameOrigin` helper function
This commit is contained in:
Tim van der Meij 2022-03-11 21:08:49 +01:00 committed by GitHub
commit bcf453cf14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 46 deletions

View file

@ -40,6 +40,7 @@ import {
PDFDocumentProxy,
PDFPageProxy,
PDFWorker,
PDFWorkerUtil,
RenderTask,
} from "../../src/display/api.js";
import {
@ -2967,4 +2968,33 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
}
);
});
describe("PDFWorkerUtil", function () {
describe("isSameOrigin", function () {
const { isSameOrigin } = PDFWorkerUtil;
it("handles invalid base URLs", function () {
// The base URL is not valid.
expect(isSameOrigin("/foo", "/bar")).toEqual(false);
// The base URL has no origin.
expect(isSameOrigin("blob:foo", "/bar")).toEqual(false);
});
it("correctly checks if the origin of both URLs matches", function () {
expect(
isSameOrigin(
"https://www.mozilla.org/foo",
"https://www.mozilla.org/bar"
)
).toEqual(true);
expect(
isSameOrigin(
"https://www.mozilla.org/foo",
"https://www.example.com/bar"
)
).toEqual(false);
});
});
});
});

View file

@ -21,7 +21,6 @@ import {
getModificationDate,
isArrayBuffer,
isAscii,
isSameOrigin,
string32,
stringToBytes,
stringToPDFString,
@ -165,31 +164,6 @@ describe("util", function () {
});
});
describe("isSameOrigin", function () {
it("handles invalid base URLs", function () {
// The base URL is not valid.
expect(isSameOrigin("/foo", "/bar")).toEqual(false);
// The base URL has no origin.
expect(isSameOrigin("blob:foo", "/bar")).toEqual(false);
});
it("correctly checks if the origin of both URLs matches", function () {
expect(
isSameOrigin(
"https://www.mozilla.org/foo",
"https://www.mozilla.org/bar"
)
).toEqual(true);
expect(
isSameOrigin(
"https://www.mozilla.org/foo",
"https://www.example.com/bar"
)
).toEqual(false);
});
});
describe("createValidAbsoluteUrl", function () {
it("handles invalid URLs", function () {
expect(createValidAbsoluteUrl(undefined, undefined)).toEqual(null);