sw/qa/filter/xml/data/format-char-style-change.odt   |binary
 xmloff/qa/unit/data/format-char-style-change.docx    |binary
 xmloff/qa/unit/text.cxx                              |   20 +++++++++++++++++++
 xmloff/source/text/XMLChangedRegionImportContext.cxx |    5 ++++
 xmloff/source/text/XMLRedlineExport.cxx              |    2 -
 5 files changed, 26 insertions(+), 1 deletion(-)

New commits:
commit df0dd5cf8fa74c07b0ca52673749f2f66208fdb8
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Aug 22 14:15:10 2025 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon Aug 25 17:29:00 2025 +0200

    tdf#167761 sw format redline, char style: fix missing encode in ODF filter
    
    Open the input DOCX, save to ODT, the named char style of the format
    redline is:
              <text:format-change loext:style-name="Strong Emphasis">
    while it should be:
              <text:format-change loext:style-name="Strong_20_Emphasis">
    
    This was not obviously a problem before, because both the import and the
    export failed to encode/decode, but it'll be a more noticable problem
    once we try to handle both direct format + char style, where autostyle
    parent names are encoded and this was not, leading to inconistency.
    
    Fix the problem similar to how it's handled for <text:span> elements for
    export in XMLTextParagraphExport::exportTextRangeSpan() and for import
    in XMLTextImportHelper::SetStyleAndAttrs(), by encoding/decoding on
    export/import.
    
    Also update sw/qa/filter/xml/data/format-char-style-change.odt, which
    had a bad style name, missing an encode before export.
    
    Change-Id: I2a9fae2c99c286d8c1c3a5e6af18f6f501e18089
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190151
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit 43104ad996bc9b292b66d9e605632407cb59c4c6)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190175
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/qa/filter/xml/data/format-char-style-change.odt 
b/sw/qa/filter/xml/data/format-char-style-change.odt
index 03cddb9eea61..c5269046fec4 100644
Binary files a/sw/qa/filter/xml/data/format-char-style-change.odt and 
b/sw/qa/filter/xml/data/format-char-style-change.odt differ
diff --git a/xmloff/qa/unit/data/format-char-style-change.docx 
b/xmloff/qa/unit/data/format-char-style-change.docx
new file mode 100644
index 000000000000..febf5dc3231d
Binary files /dev/null and b/xmloff/qa/unit/data/format-char-style-change.docx 
differ
diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx
index a6a90f0587c9..a82e62ac6e30 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -1353,6 +1353,26 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, 
testRedlineFormatCharPropsImport)
     CPPUNIT_ASSERT_EQUAL(24.f, fCharheight);
 }
 
+CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testRedlineFormatCharStyleExport)
+{
+    // Given a document with a format redline, the redline contains the old 
char style:
+    loadFromFile(u"format-char-style-change.docx");
+
+    // When exporting the document to ODT:
+    save(u"writer8"_ustr);
+
+    // Then make sure the style name is encoded:
+    xmlDocUniquePtr pXmlDoc = parseExport(u"content.xml"_ustr);
+    assertXPath(pXmlDoc, 
"//text:tracked-changes/text:changed-region/text:format-change");
+    OUString aStyleName = getXPath(
+        pXmlDoc, 
"//text:tracked-changes/text:changed-region/text:format-change", "style-name");
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: Strong_20_Emphasis
+    // - Actual  : Strong Emphasis
+    // i.e. the style name was not encoded.
+    CPPUNIT_ASSERT_EQUAL(u"Strong_20_Emphasis"_ustr, aStyleName);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/text/XMLChangedRegionImportContext.cxx 
b/xmloff/source/text/XMLChangedRegionImportContext.cxx
index d3ee8e336168..6b80b5dc1d65 100644
--- a/xmloff/source/text/XMLChangedRegionImportContext.cxx
+++ b/xmloff/source/text/XMLChangedRegionImportContext.cxx
@@ -170,6 +170,11 @@ void XMLChangedRegionImportContext::SetChangeInfo(
             m_aStyleName = pStyle->GetParentName();
         }
     }
+    if (!m_aStyleName.isEmpty())
+    {
+        // We have a named character style name, decode it.
+        m_aStyleName = 
GetImport().GetStyleDisplayName(XmlStyleFamily::TEXT_TEXT, m_aStyleName);
+    }
 
     util::DateTime aDateTime;
     if (::sax::Converter::parseDateTime(aDateTime, rDate))
diff --git a/xmloff/source/text/XMLRedlineExport.cxx 
b/xmloff/source/text/XMLRedlineExport.cxx
index 4357e5c11ffb..9eab647b1662 100644
--- a/xmloff/source/text/XMLRedlineExport.cxx
+++ b/xmloff/source/text/XMLRedlineExport.cxx
@@ -376,7 +376,7 @@ void XMLRedlineExport::ExportChangedRegion(
             OUString sStyle = 
rExport.GetTextParagraphExport()->FindTextStyle(xAutoStyle, bIsUICharStyle, 
bHasAutoStyle);
             if (!sStyle.isEmpty())
             {
-                rExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_STYLE_NAME, 
sStyle);
+                rExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_STYLE_NAME, 
rExport.EncodeStyleName(sStyle));
             }
         }
 

Reply via email to