Modern Apps git

← Modern-Apps.git

office: fix malformed manifest.xml written on save

Commit
23b18594cb3c1ff294a37c271e92e1aaddb8330c
Author
Vayun Mathur <[email protected]>
When
2026-11-07 20:10 UTC (28 days ago)
Parents
05b6fca
Symptom: every ODF package written by OdfWriter.save carried a
META-INF/manifest.xml that was not well-formed XML, so strict
readers (LibreOffice, validators, other ODF tools) could reject
or mishandle files this app saved.

Root cause: buildManifest concatenated the manifest:version
attribute without a separating space and without quotes around
1.3 on the root element, and repeated the bogus attribute on the
root file-entry.

Fix: emit manifest:version="1.3" correctly on the manifest
element and drop it from the root file-entry.

Verification: new Slice4ImportExportTest.savedManifestIsWellFormedXml
parses the written manifest with a strict XML parser; targeted
:office:testDevUnitTest for Slice4ImportExportTest passes.

Diff

office/src/main/java/com/vayunmathur/office/odf/OdfWriter.kt
diff --git a/office/src/main/java/com/vayunmathur/office/odf/OdfWriter.kt b/office/src/main/java/com/vayunmathur/office/odf/OdfWriter.ktindex dc6f1b6f60..5dee522def 100644--- a/office/src/main/java/com/vayunmathur/office/odf/OdfWriter.kt+++ b/office/src/main/java/com/vayunmathur/office/odf/OdfWriter.kt@@ -237,10 +237,8 @@ object OdfWriter {         val mime = documentMime(document)         val sb = StringBuilder()         sb.append("""<?xml version="1.0" encoding="UTF-8"?>""")-        sb.append("""<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"" +-            "manifest:version="1.3">""")-        sb.append("""<manifest:file-entry manifest:full-path="/"" +-            "manifest:version="1.3" manifest:media-type="$mime"/>""")+        sb.append("""<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.3">""")+        sb.append("""<manifest:file-entry manifest:full-path="/" manifest:media-type="$mime"/>""")         // Embedded-object directory entries (declared first so readers register the sub-documents).         for ((path, type) in extra) {             if (path.endsWith("/")) {
office/src/test/java/com/vayunmathur/office/odf/Slice4ImportExportTest.kt
diff --git a/office/src/test/java/com/vayunmathur/office/odf/Slice4ImportExportTest.kt b/office/src/test/java/com/vayunmathur/office/odf/Slice4ImportExportTest.ktindex 6eb1fb1ed4..bd0b77038d 100644--- a/office/src/test/java/com/vayunmathur/office/odf/Slice4ImportExportTest.kt+++ b/office/src/test/java/com/vayunmathur/office/odf/Slice4ImportExportTest.kt@@ -226,6 +226,26 @@ class Slice4ImportExportTest {         }     } +    @Test fun savedManifestIsWellFormedXml() {+        val out = File(context.cacheDir, "slice4-manifest.odt")+        out.delete()+        outTarget = out+        try {+            OdfWriter.save(context, null, sampleDoc(), contentUri("slice4-manifest.odt"))+            val manifest = java.util.zip.ZipFile(out).use { z ->+                z.getInputStream(z.getEntry("META-INF/manifest.xml")).bufferedReader().readText()+            }+            // Must parse as XML (previously manifest:version was unquoted/misplaced).+            val parsed = javax.xml.parsers.DocumentBuilderFactory.newInstance()+                .newDocumentBuilder().parse(manifest.byteInputStream())+            kotlin.test.assertEquals("manifest:manifest", parsed.documentElement.tagName)+            kotlin.test.assertTrue(manifest.contains("manifest:media-type="), manifest)+        } finally {+            out.delete()+            outTarget = null+        }+    }+     @Test fun saveAsDelegatesToSave() {         val out = File(context.cacheDir, "slice4-saveas.odt")         out.delete()