Merge pull request #16005 from Snuffleupagus/rm-isEmptyObj
Remove the `isEmptyObj` unit-test helper function
This commit is contained in:
commit
eb341cadd7
@ -57,7 +57,7 @@ class MetadataParser {
|
|||||||
throw new Error(`_repair: ${name} isn't defined.`);
|
throw new Error(`_repair: ${name} isn't defined.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const charBuf = [];
|
const charBuf = [">"];
|
||||||
for (let i = 0, ii = bytes.length; i < ii; i += 2) {
|
for (let i = 0, ii = bytes.length; i < ii; i += 2) {
|
||||||
const code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
|
const code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
|
||||||
if (
|
if (
|
||||||
@ -74,7 +74,7 @@ class MetadataParser {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ">" + charBuf.join("");
|
return charBuf.join("");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,10 +13,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { isEmptyObj } from "./test_utils.js";
|
|
||||||
import { Metadata } from "../../src/display/metadata.js";
|
import { Metadata } from "../../src/display/metadata.js";
|
||||||
import { MetadataParser } from "../../src/core/metadata_parser.js";
|
import { MetadataParser } from "../../src/core/metadata_parser.js";
|
||||||
|
|
||||||
|
const emptyObj = Object.create(null);
|
||||||
|
|
||||||
function createMetadata(data) {
|
function createMetadata(data) {
|
||||||
const metadataParser = new MetadataParser(data);
|
const metadataParser = new MetadataParser(data);
|
||||||
return new Metadata(metadataParser.serializable);
|
return new Metadata(metadataParser.serializable);
|
||||||
@ -136,7 +137,7 @@ describe("metadata", function () {
|
|||||||
'<?xpacket end="w"?>';
|
'<?xpacket end="w"?>';
|
||||||
const metadata = createMetadata(data);
|
const metadata = createMetadata(data);
|
||||||
|
|
||||||
expect(isEmptyObj(metadata.getAll())).toEqual(true);
|
expect(metadata.getAll()).toEqual(emptyObj);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should gracefully handle "junk" before the actual metadata (issue 10395)', function () {
|
it('should gracefully handle "junk" before the actual metadata (issue 10395)', function () {
|
||||||
@ -228,7 +229,7 @@ describe("metadata", function () {
|
|||||||
'</rdf:RDF></x:xmpmeta><?xpacket end="w"?>';
|
'</rdf:RDF></x:xmpmeta><?xpacket end="w"?>';
|
||||||
const metadata = createMetadata(data);
|
const metadata = createMetadata(data);
|
||||||
|
|
||||||
expect(isEmptyObj(metadata.getAll())).toEqual(true);
|
expect(metadata.getAll()).toEqual(emptyObj);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not be vulnerable to the billion laughs attack", function () {
|
it("should not be vulnerable to the billion laughs attack", function () {
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
import { NullStream, StringStream } from "../../src/core/stream.js";
|
import { NullStream, StringStream } from "../../src/core/stream.js";
|
||||||
import { Page, PDFDocument } from "../../src/core/document.js";
|
import { Page, PDFDocument } from "../../src/core/document.js";
|
||||||
import { assert } from "../../src/shared/util.js";
|
|
||||||
import { isNodeJS } from "../../src/shared/is_node.js";
|
import { isNodeJS } from "../../src/shared/is_node.js";
|
||||||
import { Ref } from "../../src/core/primitives.js";
|
import { Ref } from "../../src/core/primitives.js";
|
||||||
|
|
||||||
@ -144,20 +143,11 @@ function createIdFactory(pageIndex) {
|
|||||||
return page._localIdFactory;
|
return page._localIdFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isEmptyObj(obj) {
|
|
||||||
assert(
|
|
||||||
typeof obj === "object" && obj !== null,
|
|
||||||
"isEmptyObj - invalid argument."
|
|
||||||
);
|
|
||||||
return Object.keys(obj).length === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
buildGetDocumentParams,
|
buildGetDocumentParams,
|
||||||
CMAP_PARAMS,
|
CMAP_PARAMS,
|
||||||
createIdFactory,
|
createIdFactory,
|
||||||
DefaultFileReaderFactory,
|
DefaultFileReaderFactory,
|
||||||
isEmptyObj,
|
|
||||||
STANDARD_FONT_DATA_URL,
|
STANDARD_FONT_DATA_URL,
|
||||||
TEST_PDFS_PATH,
|
TEST_PDFS_PATH,
|
||||||
XRefMock,
|
XRefMock,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user