diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-04-14 18:31:32 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-04-14 19:17:39 +0200 |
commit | 21f7dc039027d8617a7032fea984f5d6e0c29de3 (patch) | |
tree | f67c869b1a46daf5a250da2998353afa1b178196 /sw | |
parent | 0da9ed723c713fd327dcc4225ffdddae9ad10939 (diff) |
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 <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/inc/txmsrt.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/tox/txmsrt.cxx | 22 |
2 files changed, 21 insertions, 3 deletions
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; } |