Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion apps/web/src/components/files/FilePreviewPanel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,16 +519,33 @@ Third}`;
expect(result.pages[0]!.html).toBe(`<table>${html}</table>`);
});

// LibreOffice writes every index as the templates it was built from, then the built index.
const indexes = [
"table-of-content",
"illustration-index",
"table-index",
"object-index",
"user-index",
"alphabetical-index",
"bibliography",
].map(
(name) =>
`<text:${name}><text:${name}-source><text:index-title-template>Index</text:index-title-template><text:${name}-entry-template><text:index-entry-text/><text:index-entry-span>: </text:index-entry-span><text:index-entry-page-number/></text:${name}-entry-template></text:${name}-source><text:index-body><text:index-title><text:p>Index</text:p></text:index-title><text:p>Field notes: 1</text:p></text:index-body></text:${name}>`,
);
it.each(["odt", "odp"] as const)("reads %s text and rejects unsupported XML", async (kind) => {
const archive = new JSZip().file(
"content.xml",
`<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"><office:body>${kind === "odt" ? "<office:text><text:p>Field notes</text:p></office:text>" : '<draw:page draw:name="Overview"><text:h>Launch plan</text:h><presentation:notes><draw:frame><draw:text-box><text:p>Speaker only</text:p></draw:text-box></draw:frame></presentation:notes></draw:page>'}</office:body></office:document-content>`,
`<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"><office:body>${kind === "odt" ? `<office:text><text:p>Field notes</text:p>${indexes.join("")}</office:text>` : '<draw:page draw:name="Overview"><text:h>Launch plan</text:h><presentation:notes><draw:frame><draw:text-box><text:p>Speaker only</text:p></draw:text-box></draw:frame></presentation:notes></draw:page>'}</office:body></office:document-content>`,
);
const result = await openDocument(archive, kind);
expect(result.type).toBe("document");
if (result.type !== "document") throw new Error("Expected document");
expect(result.pages[0]!.html).toContain(kind === "odt" ? "Field notes" : "Launch plan");
expect(result.pages[0]!.html).not.toContain("Speaker only");
if (kind === "odt")
expect(result.pages[0]!.html).toBe(
`<p>Field notes</p>${"<p>Index</p><p>Field notes: 1</p>".repeat(indexes.length)}`,
);
for (const source of [
'<!DOCTYPE x [<!ENTITY external SYSTEM "file:///etc/passwd">]><x>&external;</x>',
'<html><body><p title="<!--">x</p><!DOCTYPE x [<!ENTITY e "boom">]><b title="-->">&e;</b></body></html>',
Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/components/files/extendedDocumentPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ async function odfHtml(node: XmlNode, archive: JSZip): Promise<string> {
"office:scripts",
"draw:object",
"draw:object-ole",
"text:table-of-content-source",
"text:illustration-index-source",
"text:table-index-source",
"text:object-index-source",
"text:user-index-source",
"text:alphabetical-index-source",
"text:bibliography-source",
].includes(node.name)
)
return "";
Expand Down
Loading