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:
commit
4619b1b568
14 changed files with 258 additions and 209 deletions
|
@ -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(
|
||||
""Ηell😂' & <W😂rld>"
|
||||
);
|
||||
});
|
||||
|
||||
it("should get a correctly encoded basic ascii string", function () {
|
||||
const str = "hello world";
|
||||
expect(encodeToXmlString(str)).toEqual(str);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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">'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();
|
||||
|
@ -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();
|
||||
|
|
|
@ -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(
|
||||
""Ηell😂' & <W😂rld>"
|
||||
);
|
||||
});
|
||||
|
||||
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);
|
||||
|
|
|
@ -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 () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue