Remove the isEmptyObj unit-test helper function

We should be able to let Jasmine simply compare directly against an actually empty Object, rather than using a manually implemented helper function for that.
This commit is contained in:
Jonas Jenwald 2023-02-04 12:26:30 +01:00
parent 25253034d5
commit 851c394e64
2 changed files with 4 additions and 13 deletions

View File

@ -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 () {

View File

@ -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,