sc/qa/uitest/calc_tests9/tdf166756_file_name_in_header_and_footer.py |   47 
++++++++++
 sc/qa/uitest/data/tdf166756_[1].ods                                  |binary
 sc/source/ui/view/printfun.cxx                                       |    7 +
 sc/source/ui/view/tabvwsh4.cxx                                       |    7 +
 4 files changed, 57 insertions(+), 4 deletions(-)

New commits:
commit 540d53505863665c43f1d4960c33bf960c543cdc
Author:     Didier Vidal <[email protected]>
AuthorDate: Thu Jan 1 12:09:10 2026 +0100
Commit:     Mike Kaganski <[email protected]>
CommitDate: Thu Jan 29 11:47:52 2026 +0100

    tdf#166756 Do not use URL encoding for file name in header and footer
    
               - Modify the URL decoding mechanism in printfun.cxx and 
tabvwsh4.cxx
               since the strings are used respectively for field prinfintg and
               field preview in edit dialog
    
               - Add a uitest thwat verifies the edit dialog
    
               (this commit does not provide any automatic test to check 
printing)
    
    Change-Id: Id0980a103d3b978ef5bb4800e8605b81698f32b7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196392
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git 
a/sc/qa/uitest/calc_tests9/tdf166756_file_name_in_header_and_footer.py 
b/sc/qa/uitest/calc_tests9/tdf166756_file_name_in_header_and_footer.py
new file mode 100644
index 000000000000..caa023f2f759
--- /dev/null
+++ b/sc/qa/uitest/calc_tests9/tdf166756_file_name_in_header_and_footer.py
@@ -0,0 +1,47 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_state_as_dict, select_pos, 
get_url_for_data_file
+
+
+class Tdf166756(UITestCase):
+
+    def test_tdf166756_edit_header_and_footer(self):
+        # Test that the filename is correctly displayed in the edit header and 
footer dialog
+        # even if the filename contains special chars taht are encoded in an 
URL
+        # This test does not cover actual printing or print preview
+        fileName="tdf166756_[1].ods"
+        fileURL = get_url_for_data_file(fileName)
+        urlFileBaseName = fileURL.split("/")[-1];
+
+        # check that the file name URL encoding is different from fileName
+        # this is the purpose of the test
+        self.assertEqual("tdf166756_%5B1%5D.ods", urlFileBaseName)
+
+        with self.ui_test.load_file(fileURL):
+
+            # Check that the file name fields in header and footer preview are 
not URL encoded
+            with 
self.ui_test.execute_dialog_through_command(".uno:PageFormatDialog") as 
xPageFormatDialog:
+                xTabControl = xPageFormatDialog.getChild("tabcontrol")
+                headerTab = "4"
+                footerTab = "5"
+                for tab in [headerTab, footerTab]:
+                    select_pos(xTabControl, tab)
+                    with 
self.ui_test.execute_dialog_through_command(".uno:EditHeaderAndFooter") as 
xHeaderDialog:
+                        xLeftTextWindow = 
xHeaderDialog.getChild("textviewWND_LEFT")
+                        content = 
get_state_as_dict(xLeftTextWindow)["Text"].split("
")
+
+                        self.assertEqual("Title: tdf166756_[1]", content[0])
+                        # check file name is not url encoded
+                        self.assertEqual("FileName: tdf166756_[1].ods", 
content[1])
+                        # check that path is not url encoded
+                        self.assertEqual("tdf166756_[1].ods", 
content[2].split("/")[-1])
+
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sc/qa/uitest/data/tdf166756_[1].ods 
b/sc/qa/uitest/data/tdf166756_[1].ods
new file mode 100644
index 000000000000..338db742c5e8
Binary files /dev/null and b/sc/qa/uitest/data/tdf166756_[1].ods differ
diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx
index a390c0be38c2..156f4c9482d1 100644
--- a/sc/source/ui/view/printfun.cxx
+++ b/sc/source/ui/view/printfun.cxx
@@ -1101,9 +1101,12 @@ void ScPrintFunc::InitParam( const ScPrintOptions* 
pOptions )
         aFieldData.aTitle = rDocShell.GetTitle();
 
     const INetURLObject& rURLObj = rDocShell.GetMedium()->GetURLObject();
-    aFieldData.aLongDocName = rURLObj.GetMainURL( 
INetURLObject::DecodeMechanism::Unambiguous );
+
+    // The doc names (long and short) are meant to be printed. They should be 
in human readable
+    // format, not with an URL encoding.
+    aFieldData.aLongDocName = 
rURLObj.GetMainURL(INetURLObject::DecodeMechanism::WithCharset);
     if ( !aFieldData.aLongDocName.isEmpty() )
-        aFieldData.aShortDocName = 
rURLObj.GetLastName(INetURLObject::DecodeMechanism::Unambiguous);
+        aFieldData.aShortDocName = 
rURLObj.GetLastName(INetURLObject::DecodeMechanism::WithCharset);
     else
         aFieldData.aShortDocName = aFieldData.aLongDocName = aFieldData.aTitle;
 
diff --git a/sc/source/ui/view/tabvwsh4.cxx b/sc/source/ui/view/tabvwsh4.cxx
index dfdb9cd95e64..354d946cf34e 100644
--- a/sc/source/ui/view/tabvwsh4.cxx
+++ b/sc/source/ui/view/tabvwsh4.cxx
@@ -2272,9 +2272,12 @@ void ScTabViewShell::FillFieldData( ScHeaderFieldData& 
rData )
         rData.aTitle = pDocShell->GetTitle();
 
     const INetURLObject& rURLObj = pDocShell->GetMedium()->GetURLObject();
-    rData.aLongDocName  = rURLObj.GetMainURL( 
INetURLObject::DecodeMechanism::Unambiguous );
+
+    // The doc names (long and short) are meant to be printed. They should be 
in human readable
+    // format, not with an URL encoding.
+    rData.aLongDocName  = 
rURLObj.GetMainURL(INetURLObject::DecodeMechanism::WithCharset);
     if ( !rData.aLongDocName.isEmpty() )
-        rData.aShortDocName = 
rURLObj.GetLastName(INetURLObject::DecodeMechanism::Unambiguous);
+        rData.aShortDocName = 
rURLObj.GetLastName(INetURLObject::DecodeMechanism::WithCharset);
     else
         rData.aShortDocName = rData.aLongDocName = rData.aTitle;
     rData.nPageNo       = 1;

Reply via email to