sc/qa/unit/data/ods/tdf170670-Blank-width-char.ods |binary
 sc/qa/unit/subsequent_export_test4.cxx             |   10 ++++++++++
 xmloff/source/style/xmlnumfi.cxx                   |    7 ++++---
 3 files changed, 14 insertions(+), 3 deletions(-)

New commits:
commit fb07ca38af165b1e367aea04aa626e073b341c8f
Author:     Laurent Balland <[email protected]>
AuthorDate: Fri Feb 13 08:01:06 2026 +0100
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sun Feb 15 18:22:33 2026 +0100

    tdf#170670 NumberFormat: fix blank width string treatment
    
    In case of 2 characters string text,
    with a delimiter as text and a blank width string like
    "-"_)
    the delimiter is now treated as text
    
    Add qa test with format of bug report:
    [>0]#,##0_);[<0](#,##0);"-"_)
    
    Change-Id: Idd4542bd186c6b6b348f6716bee2fd5055f2c83f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199314
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/sc/qa/unit/data/ods/tdf170670-Blank-width-char.ods 
b/sc/qa/unit/data/ods/tdf170670-Blank-width-char.ods
new file mode 100644
index 000000000000..50918deb662f
Binary files /dev/null and b/sc/qa/unit/data/ods/tdf170670-Blank-width-char.ods 
differ
diff --git a/sc/qa/unit/subsequent_export_test4.cxx 
b/sc/qa/unit/subsequent_export_test4.cxx
index 341d39aa7423..721bd54075eb 100644
--- a/sc/qa/unit/subsequent_export_test4.cxx
+++ b/sc/qa/unit/subsequent_export_test4.cxx
@@ -1681,6 +1681,16 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, 
testBlankWidthCharacter)
     // save to XLSX and reload
     saveAndReload(TestFilter::XLSX);
     lcl_TestNumberFormat(*getScDoc(), u"_-?0;-?0;_-?0;@"_ustr);
+
+    createScDoc("ods/tdf170670-Blank-width-char.ods");
+
+    // save to ODS and reload
+    saveAndReload(TestFilter::ODS);
+    lcl_TestNumberFormat(*getScDoc(), u"[>0]#,##0_);[<0](#,##0);\"-\"_)"_ustr);
+
+    // save to XLSX and reload
+    saveAndReload(TestFilter::XLSX);
+    lcl_TestNumberFormat(*getScDoc(), u"#,##0_);\(#,##0\);-_)"_ustr);
 }
 
 CPPUNIT_TEST_FIXTURE(ScExportTest4, testEmbeddedTextInDecimal)
diff --git a/xmloff/source/style/xmlnumfi.cxx b/xmloff/source/style/xmlnumfi.cxx
index 2b560814405f..24f8469d9095 100644
--- a/xmloff/source/style/xmlnumfi.cxx
+++ b/xmloff/source/style/xmlnumfi.cxx
@@ -530,13 +530,13 @@ static bool lcl_ValidChar( sal_Unicode cChar, const 
SvXMLNumFormatContext& rPare
     return false;
 }
 
-static void lcl_EnquoteIfNecessary( OUStringBuffer& rContent, const 
SvXMLNumFormatContext& rParent )
+static void lcl_EnquoteIfNecessary( OUStringBuffer& rContent, const 
SvXMLNumFormatContext& rParent, const bool bIsBlankWidthStringEmpty = true )
 {
     bool bQuote = true;
     sal_Int32 nLength = rContent.getLength();
     const SvXMLStylesTokens nFormatType = rParent.GetType();
 
-    if (nFormatType != SvXMLStylesTokens::BOOLEAN_STYLE &&
+    if (nFormatType != SvXMLStylesTokens::BOOLEAN_STYLE && 
bIsBlankWidthStringEmpty &&
             ((nLength == 1 && lcl_ValidChar( rContent[0], rParent)) ||
              (nLength == 2 &&
               ((rContent[0] == ' ' && rContent[1] == '-') ||
@@ -547,6 +547,7 @@ static void lcl_EnquoteIfNecessary( OUStringBuffer& 
rContent, const SvXMLNumForm
         //  Or space followed by minus (used in currency formats) that would
         //  lead to almost duplicated formats with built-in formats just with
         //  the difference of quotes.
+        //  tdf#170670: except if it is inside a blank width string
         bQuote = false;
     }
     else if ( nFormatType == SvXMLStylesTokens::PERCENTAGE_STYLE && nLength > 
1 )
@@ -974,7 +975,7 @@ void SvXMLNumFmtElementContext::endFastElement(sal_Int32 )
             }
             if ( !aContent.isEmpty() )
             {
-                lcl_EnquoteIfNecessary( aContent, rParent );
+                lcl_EnquoteIfNecessary( aContent, rParent, 
sBlankWidthString.isEmpty() );
                 if ( !sBlankWidthString.isEmpty() )
                 {
                     lcl_InsertBlankWidthChars( sBlankWidthString, aContent );

Reply via email to