sw/source/core/inc/txmsrt.hxx |    2 +-
 sw/source/core/tox/txmsrt.cxx |   22 ++++++++++++++++++++--
 2 files changed, 21 insertions(+), 3 deletions(-)

New commits:
commit 21f7dc039027d8617a7032fea984f5d6e0c29de3
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Apr 14 18:31:32 2021 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Apr 14 19:17:39 2021 +0200

    sw bibliography, refer to a page: also de-duplicate relative URLs
    
    Relative URLs have to be converted to absolute ones, otherwise
    INetURLObject can't clear the mark (fragment) part of it. Then convert
    back, so the document remains portable.
    
    Change-Id: Idd9a3de045784a0430c20b689b2b3344b1e92cb5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114104
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/source/core/inc/txmsrt.hxx b/sw/source/core/inc/txmsrt.hxx
index 873e683c451e..ac89aab96c1b 100644
--- a/sw/source/core/inc/txmsrt.hxx
+++ b/sw/source/core/inc/txmsrt.hxx
@@ -299,7 +299,7 @@ public:
     OUString GetText(sal_uInt16 nAuthField, const SwRootFrame* pLayout) const;
 
     /// Gets the URL of the underlying SwAuthEntry, ignoring its page number.
-    static OUString GetSourceURL(const OUString& rText);
+    OUString GetSourceURL(const OUString& rText) const;
 };
 
 #endif // INCLUDED_SW_SOURCE_CORE_INC_TXMSRT_HXX
diff --git a/sw/source/core/tox/txmsrt.cxx b/sw/source/core/tox/txmsrt.cxx
index 881ea6e3c686..dade7ad0c5b2 100644
--- a/sw/source/core/tox/txmsrt.cxx
+++ b/sw/source/core/tox/txmsrt.cxx
@@ -42,6 +42,7 @@
 
 #include <strings.hrc>
 #include <reffld.hxx>
+#include <docsh.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -842,15 +843,32 @@ OUString SwTOXAuthority::GetText(sal_uInt16 nAuthField, 
const SwRootFrame* pLayo
     return sText;
 }
 
-OUString SwTOXAuthority::GetSourceURL(const OUString& rText)
+OUString SwTOXAuthority::GetSourceURL(const OUString& rText) const
 {
     OUString aText = rText;
-    INetURLObject aObject(aText);
+
+    SwDoc* pDoc = 
static_cast<SwAuthorityFieldType*>(m_rField.GetField()->GetTyp())->GetDoc();
+    SwDocShell* pDocShell = pDoc->GetDocShell();
+    OUString aBasePath = pDocShell->getDocumentBaseURL();
+    OUString aAbs
+        = INetURLObject::GetAbsURL(aBasePath, aText, 
INetURLObject::EncodeMechanism::WasEncoded,
+                                   
INetURLObject::DecodeMechanism::WithCharset);
+    bool bRelative = aAbs != aText;
+
+    INetURLObject aObject(aAbs);
     if (aObject.GetMark().startsWith("page="))
     {
         aObject.SetMark(OUString());
         aText = aObject.GetMainURL(INetURLObject::DecodeMechanism::NONE);
     }
+
+    if (bRelative)
+    {
+        aText
+            = INetURLObject::GetRelURL(aBasePath, aText, 
INetURLObject::EncodeMechanism::WasEncoded,
+                                       
INetURLObject::DecodeMechanism::WithCharset);
+    }
+
     return aText;
 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to