vcl/qa/cppunit/pdfexport/pdfexport.cxx | 6 ++++++ vcl/source/gdi/pdfwriter_impl.cxx | 16 ++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-)
New commits: commit da7b06425155938fb0d02c6c178d63fd95ad0cd4 Author: Dr. David Alan Gilbert <d...@treblig.org> AuthorDate: Sat Nov 13 01:33:06 2021 +0000 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Thu Mar 10 10:26:23 2022 +0100 tdf#143216: pdfwriter: Don't treat semi-valid URIs as local paths Currently the PDF writer treats URIs that are rejected by INetURIObject, as local files, and prepends a path to them. For URIs that are valid according to the basic URI syntax, but unhandled by INetURIObject (such as http://user:password@domain) this produces a confusing result with a ./uri in the PDF. Avoid the prefixing where the URI follows the basic URI syntax, even if INetURIObject didn't like it. Change-Id: I87c599885a40fd7101c678ae79f83f594d0f23ee Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125202 Reviewed-by: Stephan Bergmann <sberg...@redhat.com> Tested-by: Jenkins Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131259 diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index b6e251509d06..8934e11c0e9f 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -2962,6 +2962,12 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testURIs) "file://localfile.odt/", true, }, + { + // tdf 143216 + "http://username:passw...@example.com", + "http://username:passw...@example.com", + true, + }, { "git://git.example.org/project/example", "git://git.example.org/project/example", diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index b5e94882a0fb..141c4f823fc1 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -47,6 +47,7 @@ #include <osl/file.hxx> #include <osl/thread.h> #include <rtl/digest.h> +#include <rtl/uri.hxx> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> #include <svl/urihelper.hxx> @@ -3280,6 +3281,7 @@ we check in the following sequence: bool bTargetHasPDFExtension = false; INetProtocol eTargetProtocol = aTargetURL.GetProtocol(); bool bIsUNCPath = false; + bool bUnparsedURI = false; // check if the protocol is a known one, or if there is no protocol at all (on target only) // if there is no protocol, make the target relative to the current document directory @@ -3292,14 +3294,14 @@ we check in the following sequence: } else { - INetURLObject aNewBase( aDocumentURL );//duplicate document URL - aNewBase.removeSegment(); //remove last segment from it, obtaining the base URL of the - //target document - aNewBase.insertName( url ); - aTargetURL = aNewBase;//reassign the new target URL + INetURLObject aNewURL(rtl::Uri::convertRelToAbs(m_aContext.BaseURL, url)); + aTargetURL = aNewURL; //reassign the new target URL + //recompute the target protocol, with the new URL //normal URL processing resumes eTargetProtocol = aTargetURL.GetProtocol(); + + bUnparsedURI = eTargetProtocol == INetProtocol::NotValid; } } @@ -3415,7 +3417,9 @@ we check in the following sequence: //substitute the fragment aTargetURL.SetMark( OStringToOUString(aLineLoc.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US) ); } - OUString aURL = aTargetURL.GetMainURL( bFileSpec ? INetURLObject::DecodeMechanism::WithCharset : INetURLObject::DecodeMechanism::NONE ); + OUString aURL = bUnparsedURI ? url : + aTargetURL.GetMainURL( bFileSpec ? INetURLObject::DecodeMechanism::WithCharset : + INetURLObject::DecodeMechanism::NONE ); appendLiteralStringEncrypt(bSetRelative ? INetURLObject::GetRelURL( m_aContext.BaseURL, aURL, INetURLObject::EncodeMechanism::WasEncoded, bFileSpec ? INetURLObject::DecodeMechanism::WithCharset : INetURLObject::DecodeMechanism::NONE