summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDr. David Alan Gilbert <dave@treblig.org>2021-11-13 01:33:06 +0000
committerStephan Bergmann <sbergman@redhat.com>2022-03-09 14:05:27 +0100
commit9579737b36e5055d5eb72abc0ace2b9b65600c76 (patch)
tree30b69e90b1f5eb5f6d798273fecebdd4a63a9c41
parentd8c5fdcb3f1e2fdaacc6a7e403a2077d93207c82 (diff)
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 <sbergman@redhat.com> Tested-by: Jenkins
-rw-r--r--vcl/qa/cppunit/pdfexport/pdfexport.cxx6
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx16
2 files changed, 16 insertions, 6 deletions
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 35ca1c9bc051..e7f2354b9118 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -3050,6 +3050,12 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testURIs)
true,
},
{
+ // tdf 143216
+ "http://username:password@example.com",
+ "http://username:password@example.com",
+ true,
+ },
+ {
"git://git.example.org/project/example",
"git://git.example.org/project/example",
true,
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 21f085fe2660..51291604fe51 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