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:
commit
bcf453cf14
4 changed files with 49 additions and 46 deletions
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue