GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): preserve literal entities in EPUB CDATA (#36595) · Pipyakas/t3code@d6244ac

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src/components/files
    • FilePreviewPanel.test.ts
    • extendedDocumentPreview.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/components/files/FilePreviewPanel.test.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/components/files/FilePreviewPanel.test.ts
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,12 @@ Third}`;
221221
it("resolves scoped ODF namespaces and explicit spreadsheet whitespace", async () => {
222222
const archive = new JSZip().file(
223223
"content.xml",
224-
'<o:document-content xmlns:o="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:t="urn:oasis:names:tc:opendocument:xmlns:table:1.0"><o:body><o:spreadsheet><t:table t:name="Accounts &amp; names"><t:table-row><t:table-cell><p xmlns="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:x="urn:oasis:names:tc:opendocument:xmlns:text:1.0">Account<s/>Name<s x:c="3"/>A<tab/>B<line-break/>C</p></t:table-cell></t:table-row></t:table></o:spreadsheet></o:body></o:document-content>',
224+
'<o:document-content xmlns:o="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:t="urn:oasis:names:tc:opendocument:xmlns:table:1.0"><o:body><o:spreadsheet><t:table t:name="Accounts &amp; names"><t:table-row><t:table-cell><p xmlns="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:x="urn:oasis:names:tc:opendocument:xmlns:text:1.0">Account<s/>Name<s x:c="3"/>A<tab/>B<line-break/>C &amp; <![CDATA[&amp;]]></p></t:table-cell></t:table-row></t:table></o:spreadsheet></o:body></o:document-content>',
225225
);
226226
const result = await openDocument(archive, "ods");
227227
if (result.type !== "ods") throw new Error("Expected workbook");
228228
expect(result.sheets[0]!.name).toBe("Accounts & names");
229-
expect(result.sheets[0]!.rows[0]).toEqual(["Account Name A\tB\nC"]);
229+
expect(result.sheets[0]!.rows[0]).toEqual(["Account Name A\tB\nC & &amp;"]);
230230
});
231231

232232
it("stops repeated slide images before encoding beyond the output budget", async () => {
@@ -439,7 +439,7 @@ Third}`;
439439
)
440440
.file(
441441
"Book/two&&&.xhtml",
442-
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><head><title>Second</title></head><body><h1>Second chapter</h1><p>A&nbsp;B &copy; &mdash; &NotEqualTilde; &amp;lt;</p><img src="cover.png" alt="&copy; &NotEqualTilde;"/></body></html>',
442+
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><head><title>Second</title></head><body><h1>Second chapter</h1><p>A&nbsp;B &copy; &mdash; &NotEqualTilde; &amp;lt;</p><pre><![CDATA[Use &amp; and &lt; literally]]></pre><img src="cover.png" alt="&copy; &NotEqualTilde;"/></body></html>',
443443
)
444444
.file(
445445
"Book/cover.png",
@@ -453,6 +453,7 @@ Third}`;
453453
if (result.type !== "document") throw new Error("Expected document");
454454
expect(result.pages.map((page) => page.title)).toEqual(["Second", "First"]);
455455
expect(result.pages[0]!.html).toContain("A\u00a0B © — ≂̸ &amp;lt;");
456+
expect(result.pages[0]!.html).toContain("<pre>Use &amp;amp; and &amp;lt; literally</pre>");
456457
expect(result.pages[0]!.html).toContain('alt="© ≂̸"');
457458
expect(result.pages[1]!.html).toContain('src="data:image/png;base64,');
458459
expect(result.pages[1]!.html).not.toMatch(/https:|script|alert/);
Collapse file

‎apps/web/src/components/files/extendedDocumentPreview.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/components/files/extendedDocumentPreview.ts
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { type OfficeWorkerResult, type NotebookCell } from "./officePreviewProto
1212
const ODS_PREVIEW_MAX_ROWS = 500;
1313
const ODS_PREVIEW_MAX_COLUMNS = 50;
1414

15+
// `text` and `attrs` hold decoded values: escaped text is decoded once, CDATA stays literal.
1516
type XmlNode = { name: string; attrs: Record<string, string>; children: XmlNode[]; text: string };
1617
type OrderedXml = { [key: string]: OrderedXml[] | Record<string, string> | string };
1718
const escape = (value: string) =>
@@ -47,6 +48,7 @@ function parseXml(source: string): XmlNode {
4748
processEntities: false,
4849
trimValues: false,
4950
parseTagValue: false,
51+
cdataPropName: "#cdata",
5052
});
5153
const ordered = parser.parse(source) as OrderedXml[];
5254
let count = 0;
@@ -60,6 +62,12 @@ function parseXml(source: string): XmlNode {
6062
if (++count > 100_000) throw new Error("This document has too much content to preview.");
6163
const name = Object.keys(item).find((key) => key !== ":@") ?? "#text";
6264
const value = item[name];
65+
if (name === "#cdata") {
66+
const literal = Array.isArray(value)
67+
? value.map((part) => part["#text"] ?? "").join("")
68+
: "";
69+
return { name: "#text", attrs: {}, children: [], text: literal };
70+
}
6371
const attrs = Object.fromEntries(
6472
Object.entries((item[":@"] ?? {}) as Record<string, string>).map(([key, value]) => [
6573
key,
@@ -91,7 +99,7 @@ function parseXml(source: string): XmlNode {
9199
Object.entries(attrs).map(([key, value]) => [expanded(key, true), value]),
92100
),
93101
children: Array.isArray(value) ? convert(value, depth + 1, namespaces) : [],
94-
text: typeof value === "string" ? value : "",
102+
text: typeof value === "string" ? decodeEntities(value) : "",
95103
};
96104
});
97105
}
@@ -116,7 +124,7 @@ function text(node: XmlNode): string {
116124
if (node.name === "text:s") return " ".repeat(repeat(node.attrs["text:c"], 100));
117125
if (node.name === "text:tab") return "\t";
118126
if (node.name === "text:line-break") return "\n";
119-
return node.name === "#text" ? decodeEntities(node.text) : node.children.map(text).join("");
127+
return node.name === "#text" ? node.text : node.children.map(text).join("");
120128
}
121129
function archivePath(base: string, href: string): string | null {
122130
if (/^(?:[a-z][a-z\d+.-]*:|\/|\\)/i.test(href)) return null;

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.