1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge pull request #14424 from Snuffleupagus/mv-addLinkAttributes

[api-minor] Move `addLinkAttributes`, `LinkTarget`, and `removeNullCharacters` into the viewer (PR 14092 follow-up)
This commit is contained in:
Tim van der Meij 2022-01-08 13:19:11 +01:00 committed by GitHub
commit 8ac0ccc227
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 231 additions and 246 deletions

View file

@ -21,6 +21,7 @@ import {
isPortraitOrientation,
isValidRotation,
parseQueryString,
removeNullCharacters,
} from "../../web/ui_utils.js";
describe("ui_utils", function () {
@ -139,6 +140,30 @@ describe("ui_utils", function () {
});
});
describe("removeNullCharacters", function () {
it("should not modify string without null characters", function () {
const str = "string without null chars";
expect(removeNullCharacters(str)).toEqual("string without null chars");
});
it("should modify string with null characters", function () {
const str = "string\x00With\x00Null\x00Chars";
expect(removeNullCharacters(str)).toEqual("stringWithNullChars");
});
it("should modify string with non-displayable characters", function () {
const str = Array.from(Array(32).keys())
.map(x => String.fromCharCode(x) + "a")
.join("");
// \x00 is replaced by an empty string.
const expected =
"a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a";
expect(removeNullCharacters(str, /* replaceInvisible */ true)).toEqual(
expected
);
});
});
describe("getPageSizeInches", function () {
it("gets page size (in inches)", function () {
const page = {

View file

@ -25,7 +25,6 @@ import {
isNum,
isSameOrigin,
isString,
removeNullCharacters,
string32,
stringToBytes,
stringToPDFString,
@ -175,30 +174,6 @@ describe("util", function () {
});
});
describe("removeNullCharacters", function () {
it("should not modify string without null characters", function () {
const str = "string without null chars";
expect(removeNullCharacters(str)).toEqual("string without null chars");
});
it("should modify string with null characters", function () {
const str = "string\x00With\x00Null\x00Chars";
expect(removeNullCharacters(str)).toEqual("stringWithNullChars");
});
it("should modify string with non-displayable characters", function () {
const str = Array.from(Array(32).keys())
.map(x => String.fromCharCode(x) + "a")
.join("");
// \x00 is replaced by an empty string.
const expected =
"a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a";
expect(removeNullCharacters(str, /* replaceInvisible */ true)).toEqual(
expected
);
});
});
describe("ReadableStream", function () {
it("should return an Object", function () {
const readable = new ReadableStream();