sc/source/filter/excel/excdoc.cxx |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

New commits:
commit 4199a5a630bb327e006649feda0d4acb6ad20309
Author:     Bayram Çiçek <bayram.ci...@collabora.com>
AuthorDate: Thu Aug 21 13:11:44 2025 +0300
Commit:     Bayram Çiçek <bayram.ci...@collabora.com>
CommitDate: Thu Aug 21 13:55:54 2025 +0200

    tdf#167689: Calc: check if XML declaration exists
    
    when exporting xl/xmlMaps.xml
    
    follow-up for https://gerrit.libreoffice.org/c/core/+/189044
    (657f0112b550a28a61aca874e301d98dade57e1d)
    
    Signed-off-by: Bayram Çiçek <bayram.ci...@collabora.com>
    Change-Id: Iac5e94774632d74f1b99a32aaa56514396b10792
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189989
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sc/source/filter/excel/excdoc.cxx 
b/sc/source/filter/excel/excdoc.cxx
index 84490825ffb5..38ab0d78b831 100644
--- a/sc/source/filter/excel/excdoc.cxx
+++ b/sc/source/filter/excel/excdoc.cxx
@@ -1292,8 +1292,11 @@ void ExcDocument::WriteXml( XclExpXmlStream& rStrm )
 
         /* we should remove <?xml version="1.0" encoding="UTF-8"?>
         XML declaration from the string as rStrm.PushStream() already adds it. 
*/
-        sal_uInt32 nXmlDeclarationLocation = sXmlMapsContent.find(">");
-        sXmlMapsContent = sXmlMapsContent.substr(nXmlDeclarationLocation + 1);
+        const std::size_t nXmlDeclarationLocation = sXmlMapsContent.find("?>");
+
+        // but there may not be an XML declaration, we should also check that.
+        if (nXmlDeclarationLocation != std::string::npos)
+            sXmlMapsContent = sXmlMapsContent.substr(nXmlDeclarationLocation + 
2);
 
         // write contents into xl/xmlMaps.xml
         rStrm.GetCurrentStream()->write(sXmlMapsContent);

Reply via email to