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
Signed-off-by: Xisco Fauli <xiscofauli@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 b6e2515..8934e11 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -2963,6 +2963,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 b5e9488..141c4f8 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