cui/source/dialogs/hlinettp.cxx               |    2 -
 sw/qa/uitest/writer_tests3/hyperlinkdialog.py |   48 ++++++++++----------------
 2 files changed, 21 insertions(+), 29 deletions(-)

New commits:
commit 2c3fc08d119989f731a46a4af357e2366d3c508c
Author:     Andreas Heinisch <andreas.heini...@yahoo.de>
AuthorDate: Mon Nov 11 17:04:41 2024 +0100
Commit:     Andreas Heinisch <andreas.heini...@yahoo.de>
CommitDate: Tue Nov 12 07:35:29 2024 +0100

    tdf#162753 - Hyperlink dialog: trim leading/trailing whitespaces of URLs
    
    Change-Id: Ic18d30239e8741f8a28e81e423d3dc223d709a93
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176409
    Tested-by: Jenkins
    Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de>

diff --git a/cui/source/dialogs/hlinettp.cxx b/cui/source/dialogs/hlinettp.cxx
index c64f8e7fa01b..2269f3447296 100644
--- a/cui/source/dialogs/hlinettp.cxx
+++ b/cui/source/dialogs/hlinettp.cxx
@@ -91,7 +91,7 @@ void SvxHyperlinkInternetTp::FillDlgFields(const OUString& 
rStrURL)
                         if (xTransferable->getTransferData(aFlavor) >>= 
aClipBoardContent)
                         {
                             // tdf#162753 - allow only syntactically valid 
hyperlink targets
-                            INetURLObject aURL(aClipBoardContent);
+                            INetURLObject aURL(o3tl::trim(aClipBoardContent));
                             if (!aURL.HasError())
                                 aStrURL
                                     = 
aURL.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous);
diff --git a/sw/qa/uitest/writer_tests3/hyperlinkdialog.py 
b/sw/qa/uitest/writer_tests3/hyperlinkdialog.py
index 1ab08e6facdc..8fa06496351a 100644
--- a/sw/qa/uitest/writer_tests3/hyperlinkdialog.py
+++ b/sw/qa/uitest/writer_tests3/hyperlinkdialog.py
@@ -107,20 +107,29 @@ class HyperlinkDialog(UITestCase):
 
     def test_tdf146576_propose_clipboard_content(self):
         with self.ui_test.create_doc_in_start_center("writer"):
-            # Insert a sample URL
             xWriterDoc = self.xUITest.getTopFocusWindow()
             xWriterEdit = xWriterDoc.getChild("writer_edit")
-            xWriterEdit.executeAction("TYPE", mkPropertyValues({"TEXT": 
"http://www.libreoffice.org"}))
 
-            # Copy URL and open the hyperlink dialog
-            self.xUITest.executeCommand(".uno:SelectAll")
-            self.xUITest.executeCommand(".uno:Copy")
-            with 
self.ui_test.execute_dialog_through_command(".uno:HyperlinkDialog", 
close_button="cancel") as xDialog:
-                xTab = xDialog.getChild("tabcontrol")
-                select_pos(xTab, "0")
-                # Check if the content of the clipboard is proposed as URL in 
the hyperlink dialog
-                xTarget = xDialog.getChild("target")
-                self.assertEqual(get_state_as_dict(xTarget)["Text"].lower(), 
"http://www.libreoffice.org/";)
+            sampleURLs = [
+                ("libreoffice", ""),
+                ("http://www.libreoffice.org";, "http://www.libreoffice.org/";),
+                ("    http://www.libreoffice.org    ", 
"http://www.libreoffice.org/";)
+            ]
+
+            # Insert sample URLs
+            for sampleURL, expectedURL in sampleURLs:
+                self.xUITest.executeCommand(".uno:SelectAll")
+                xWriterEdit.executeAction("TYPE", mkPropertyValues({"TEXT": 
sampleURL}))
+
+                # Copy URL and open the hyperlink dialog
+                self.xUITest.executeCommand(".uno:SelectAll")
+                self.xUITest.executeCommand(".uno:Copy")
+                with 
self.ui_test.execute_dialog_through_command(".uno:HyperlinkDialog", 
close_button="cancel") as xDialog:
+                    xTab = xDialog.getChild("tabcontrol")
+                    select_pos(xTab, "0")
+                    # Check if the content of the clipboard is proposed as 
expected
+                    xTarget = xDialog.getChild("target")
+                    
self.assertEqual(get_state_as_dict(xTarget)["Text"].lower(), expectedURL)
 
     def test_tdf162753_propose_clipboard_content_internet(self):
         with self.ui_test.create_doc_in_start_center("writer"):
@@ -147,23 +156,6 @@ class HyperlinkDialog(UITestCase):
                 xTarget = xDialog.getChild("target")
                 self.assertEqual(get_state_as_dict(xTarget)["Text"].lower(), 
"http://www.libreoffice.org/";)
 
-    def test_tdf162753_propose_invalid_clipboard_content(self):
-        with self.ui_test.create_doc_in_start_center("writer"):
-            # Insert an invalid sample URL
-            xWriterDoc = self.xUITest.getTopFocusWindow()
-            xWriterEdit = xWriterDoc.getChild("writer_edit")
-            xWriterEdit.executeAction("TYPE", mkPropertyValues({"TEXT": 
"libreoffice"}))
-
-            # Copy URL and open the hyperlink dialog
-            self.xUITest.executeCommand(".uno:SelectAll")
-            self.xUITest.executeCommand(".uno:Copy")
-            with 
self.ui_test.execute_dialog_through_command(".uno:HyperlinkDialog", 
close_button="cancel") as xDialog:
-                xTab = xDialog.getChild("tabcontrol")
-                select_pos(xTab, "0")
-                # Check if the content of the clipboard is not proposed as URL 
in the hyperlink dialog
-                xTarget = xDialog.getChild("target")
-                self.assertEqual(get_state_as_dict(xTarget)["Text"], "")
-
     def test_tdf141166(self):
         # Skip this test for --with-help=html and --with-help=online, as that 
would fail with a
         # DialogNotExecutedException("did not execute a dialog for a blocking 
action") thrown from

Reply via email to