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

[api-minor] Move removeNullCharacters into the viewer

This helper function has never been used in e.g. the worker-thread, hence its placement in `src/shared/util.js` led to a *small* amount of unnecessary duplication.
After the previous patches this helper function is now *only* used in the viewer, hence it no longer seems necessary to expose it through the official API.

*Please note:* It seems somewhat unlikely that third-party users were relying *directly* on this helper function, which is why it's not being exported as part of the viewer components. (If necessary, we can always change this later on.)
This commit is contained in:
Jonas Jenwald 2022-01-03 14:11:12 +01:00
parent 00aa9811e6
commit 7b8794b37e
7 changed files with 46 additions and 48 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();