1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-21 23:58:07 +02:00

Merge pull request #12997 from Snuffleupagus/metadata-worker

Move the Metadata parsing to the worker-thread
This commit is contained in:
Tim van der Meij 2021-02-17 20:57:46 +01:00 committed by GitHub
commit 4619b1b568
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 258 additions and 209 deletions

View file

@ -15,6 +15,7 @@
import { Dict, Ref } from "../../src/core/primitives.js";
import {
encodeToXmlString,
escapePDFName,
getInheritableProperty,
isWhiteSpace,
@ -218,4 +219,18 @@ describe("core_utils", function () {
);
});
});
describe("encodeToXmlString", function () {
it("should get a correctly encoded string with some entities", function () {
const str = "\"\u0397ell😂' & <W😂rld>";
expect(encodeToXmlString(str)).toEqual(
"&quot;&#x397;ell&#x1F602;&apos; &amp; &lt;W&#x1F602;rld&gt;"
);
});
it("should get a correctly encoded basic ascii string", function () {
const str = "hello world";
expect(encodeToXmlString(str)).toEqual(str);
});
});
});

View file

@ -15,6 +15,12 @@
import { isEmptyObj } from "./test_utils.js";
import { Metadata } from "../../src/display/metadata.js";
import { MetadataParser } from "../../src/core/metadata_parser.js";
function createMetadata(data) {
const metadataParser = new MetadataParser(data);
return new Metadata(metadataParser.serializable);
}
describe("metadata", function () {
it("should handle valid metadata", function () {
@ -24,7 +30,7 @@ describe("metadata", function () {
"<rdf:Description xmlns:dc='http://purl.org/dc/elements/1.1/'>" +
'<dc:title><rdf:Alt><rdf:li xml:lang="x-default">Foo bar baz</rdf:li>' +
"</rdf:Alt></dc:title></rdf:Description></rdf:RDF></x:xmpmeta>";
const metadata = new Metadata(data);
const metadata = createMetadata(data);
expect(metadata.has("dc:title")).toBeTruthy();
expect(metadata.has("dc:qux")).toBeFalsy();
@ -42,7 +48,7 @@ describe("metadata", function () {
"<rdf:Description xmlns:dc='http://purl.org/dc/elements/1.1/'>" +
"<dc:title>\\376\\377\\000P\\000D\\000F\\000&</dc:title>" +
"</rdf:Description></rdf:RDF></x:xmpmeta>";
const metadata = new Metadata(data);
const metadata = createMetadata(data);
expect(metadata.has("dc:title")).toBeTruthy();
expect(metadata.has("dc:qux")).toBeFalsy();
@ -85,7 +91,7 @@ describe("metadata", function () {
"<dc:creator><rdf:Seq><rdf:li>\\376\\377\\000O\\000D\\000I\\000S" +
"</rdf:li></rdf:Seq></dc:creator></rdf:Description></rdf:RDF>" +
"</x:xmpmeta>";
const metadata = new Metadata(data);
const metadata = createMetadata(data);
expect(metadata.has("dc:title")).toBeTruthy();
expect(metadata.has("dc:qux")).toBeFalsy();
@ -128,7 +134,7 @@ describe("metadata", function () {
"</rdf:RDF>" +
"</x:xmpmeta>" +
'<?xpacket end="w"?>';
const metadata = new Metadata(data);
const metadata = createMetadata(data);
expect(isEmptyObj(metadata.getAll())).toEqual(true);
});
@ -159,7 +165,7 @@ describe("metadata", function () {
'<dc:title><rdf:Alt><rdf:li xml:lang="x-default"></rdf:li>' +
"</rdf:Alt></dc:title><dc:format>application/pdf</dc:format>" +
'</rdf:Description></rdf:RDF></x:xmpmeta><?xpacket end="w"?>';
const metadata = new Metadata(data);
const metadata = createMetadata(data);
expect(metadata.has("dc:title")).toBeTruthy();
expect(metadata.has("dc:qux")).toBeFalsy();
@ -191,7 +197,7 @@ describe("metadata", function () {
"<dc:title><rdf:Alt>" +
'<rdf:li xml:lang="x-default">&apos;Foo bar baz&apos;</rdf:li>' +
"</rdf:Alt></dc:title></rdf:Description></rdf:RDF></x:xmpmeta>";
const metadata = new Metadata(data);
const metadata = createMetadata(data);
expect(metadata.has("dc:title")).toBeTruthy();
expect(metadata.has("dc:qux")).toBeFalsy();
@ -220,7 +226,7 @@ describe("metadata", function () {
"<xmpMM:DocumentID>uuid:00000000-1c84-3cf9-89ba-bef0e729c831" +
"</xmpMM:DocumentID></rdf:Description>" +
'</rdf:RDF></x:xmpmeta><?xpacket end="w"?>';
const metadata = new Metadata(data);
const metadata = createMetadata(data);
expect(isEmptyObj(metadata.getAll())).toEqual(true);
});
@ -249,7 +255,7 @@ describe("metadata", function () {
" </dc:title>" +
" </rdf:Description>" +
"</rdf:RDF>";
const metadata = new Metadata(data);
const metadata = createMetadata(data);
expect(metadata.has("dc:title")).toBeTruthy();
expect(metadata.has("dc:qux")).toBeFalsy();

View file

@ -17,7 +17,6 @@ import {
bytesToString,
createPromiseCapability,
createValidAbsoluteUrl,
encodeToXmlString,
escapeString,
getModificationDate,
isArrayBuffer,
@ -335,20 +334,6 @@ describe("util", function () {
});
});
describe("encodeToXmlString", function () {
it("should get a correctly encoded string with some entities", function () {
const str = "\"\u0397ell😂' & <W😂rld>";
expect(encodeToXmlString(str)).toEqual(
"&quot;&#x397;ell&#x1F602;&apos; &amp; &lt;W&#x1F602;rld&gt;"
);
});
it("should get a correctly encoded basic ascii string", function () {
const str = "hello world";
expect(encodeToXmlString(str)).toEqual(str);
});
});
describe("isAscii", function () {
it("handles ascii/non-ascii strings", function () {
expect(isAscii("hello world")).toEqual(true);

View file

@ -14,7 +14,7 @@
*/
import { parseXFAPath } from "../../src/core/core_utils.js";
import { SimpleXMLParser } from "../../src/shared/xml_parser.js";
import { SimpleXMLParser } from "../../src/core/xml_parser.js";
describe("XML", function () {
describe("searchNode", function () {