library-ui: declare xmlns:meta in flat ODF root (fixes 'undefined prefix: meta' on reparse)
- Commit
096dec74c80e092cc045f30d7e7e7a62cc23be02- Author
- Vayun Mathur <[email protected]>
- When
- 2026-07-06 14:57 UTC (5 months ago)
- Parents
b46ea3d
Diff
library/ui/src/main/java/com/vayunmathur/library/ui/odf/OdfSerializer.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/odf/OdfSerializer.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/odf/OdfSerializer.ktindex d2e700d432..c2e55e5cbb 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/odf/OdfSerializer.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/odf/OdfSerializer.kt@@ -1051,6 +1051,7 @@ object OdfSerializer { sb.append(""" xmlns:xlink="http://www.w3.org/1999/xlink"""") sb.append(""" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"""") sb.append(""" xmlns:dc="http://purl.org/dc/elements/1.1/"""")+ sb.append(""" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"""") sb.append(""" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"""") sb.append(""" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"""") sb.append(""" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"""")
library/ui/src/test/java/com/vayunmathur/library/ui/odf/SerializeFlatNamespaceTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/odf/SerializeFlatNamespaceTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/odf/SerializeFlatNamespaceTest.ktnew file mode 100644index 0000000000..77380974d7--- /dev/null+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/odf/SerializeFlatNamespaceTest.kt@@ -0,0 +1,23 @@+package com.vayunmathur.library.ui.odf++import org.junit.Assert.assertTrue+import org.junit.Test++class SerializeFlatNamespaceTest {+ @Test+ fun flat_declares_meta_namespace_before_use() {+ val doc = OdfDocument.TextDocument(+ title = "Hello",+ content = listOf(OdfContentBlock.Paragraph(OdfParagraph(listOf(OdfSpan("hi")))))+ )+ val flat = OdfSerializer.serializeFlat(doc)+ assertTrue("flat ODF must be a single office:document", flat.contains("<office:document"))+ // Any meta:-prefixed element must be preceded by an xmlns:meta declaration on the root.+ if (flat.contains("<meta:")) {+ assertTrue(+ "xmlns:meta must be declared before the first <meta: element",+ flat.substringBefore("<meta:").contains("xmlns:meta=")+ )+ }+ }+}