From 6c9a86a6392662f1115d3fe6b793a451101429b7 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 15 Apr 2021 13:07:37 +0200 Subject: sw: avoid rel<->abs URL conversion in SwTOXAuthority::GetSourceURL() Suggested at , turns out we can clear the fragment of a relative URL without converting to an absolute one, which is less code and probably behaves better with a not yet saved document (empty base URL). Change-Id: I8cee210aada10a3e8049e5b7a6921f1be4445bb8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114124 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sw/source/core/inc/txmsrt.hxx | 2 +- sw/source/core/tox/txmsrt.cxx | 35 +++++++++++++++++------------------ 2 files changed, 18 insertions(+), 19 deletions(-) (limited to 'sw') diff --git a/sw/source/core/inc/txmsrt.hxx b/sw/source/core/inc/txmsrt.hxx index ac89aab96c1b..873e683c451e 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. - OUString GetSourceURL(const OUString& rText) const; + static OUString GetSourceURL(const OUString& rText); }; #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 dade7ad0c5b2..193dc1d48a71 100644 --- a/sw/source/core/tox/txmsrt.cxx +++ b/sw/source/core/tox/txmsrt.cxx @@ -17,9 +17,12 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include + #include #include #include +#include #include #include #include @@ -843,30 +846,26 @@ OUString SwTOXAuthority::GetText(sal_uInt16 nAuthField, const SwRootFrame* pLayo return sText; } -OUString SwTOXAuthority::GetSourceURL(const OUString& rText) const +OUString SwTOXAuthority::GetSourceURL(const OUString& rText) { OUString aText = rText; - SwDoc* pDoc = static_cast(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=")) + uno::Reference xUriReferenceFactory + = uri::UriReferenceFactory::create(comphelper::getProcessComponentContext()); + uno::Reference xUriRef; + try { - aObject.SetMark(OUString()); - aText = aObject.GetMainURL(INetURLObject::DecodeMechanism::NONE); + xUriRef = xUriReferenceFactory->parse(aText); } - - if (bRelative) + catch (const uno::Exception& rException) + { + SAL_WARN("sw.core", + "SwTOXAuthority::GetSourceURL: failed to parse url: " << rException.Message); + } + if (xUriRef.is() && xUriRef->getFragment().startsWith("page=")) { - aText - = INetURLObject::GetRelURL(aBasePath, aText, INetURLObject::EncodeMechanism::WasEncoded, - INetURLObject::DecodeMechanism::WithCharset); + xUriRef->clearFragment(); + aText = xUriRef->getUriReference(); } return aText; -- cgit v1.2.3