sw/source/uibase/docvw/edtwin2.cxx |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

New commits:
commit 04c16c7b0b517cb868c0e1b102bc3d59862536e3
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sat Aug 30 03:04:08 2025 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sat Aug 30 17:25:21 2025 +0200

    tdf#168184: let fetchBookmarkedValueFromInternalLink return original
    
    ... URL, when it doesn't detect an internal hyperlink, or doesn't
    find a bookmarked value for it. The original string should show in
    the tooltip in that case.
    
    Also use startsWith, to make sure we don't dereference first char
    of an empty string.
    
    Change-Id: I0034fdad8148b26e7db59fc6e4e4599c4e87ed6f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190403
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/source/uibase/docvw/edtwin2.cxx 
b/sw/source/uibase/docvw/edtwin2.cxx
index c22970d5acf2..d087cc2c666c 100644
--- a/sw/source/uibase/docvw/edtwin2.cxx
+++ b/sw/source/uibase/docvw/edtwin2.cxx
@@ -330,16 +330,16 @@ namespace
 
 /** Fetches the text enclosed by the bookmark, resolved from the internal 
(input) link
  *
- * If a bookmark doesn't exist, return an empty string.
+ * If a bookmark doesn't exist, return the original string.
  **/
-OUString fetchBookmarkedValueFromInternalLink(std::u16string_view sURL, 
SwWrtShell& rShell)
+OUString fetchBookmarkedValueFromInternalLink(const OUString& sURL, 
SwWrtShell& rShell)
 {
     // Check if the URL is an internal link (starts with '#')
-    if (sURL[0] != '#')
-        return OUString();
+    if (!sURL.startsWith("#"))
+        return sURL;
 
     IDocumentMarkAccess* pMarkAccess = rShell.getIDocumentMarkAccess();
-    auto ppBookmark = 
pMarkAccess->findBookmark(SwMarkName(OUString(sURL.substr(1))));
+    auto ppBookmark = pMarkAccess->findBookmark(SwMarkName(sURL.copy(1)));
     if (ppBookmark != pMarkAccess->getBookmarksEnd()
         && IDocumentMarkAccess::GetType(**ppBookmark)
             == IDocumentMarkAccess::MarkType::CROSSREF_HEADING_BOOKMARK)
@@ -363,7 +363,7 @@ OUString 
fetchBookmarkedValueFromInternalLink(std::u16string_view sURL, SwWrtShe
             }
         }
     }
-    return OUString();
+    return sURL;
 }
 }
 

Reply via email to