tools: try to work around DavGetHTTPFromUNCPath() not URL-encoding path

This was added in commit 20b1e6440a
"tdf#126121: WebDAV redirection detection" and it works fine when i test
it on my local Windows 10, returning an URL with encoded path.

The logs from the customer system however show a http URL containing an
unencoded ' ' in the path, which curl_url_set chokes on.

Try to encode the returned URL with rtl_UriEncodeKeepEscapes, which
should hopefully work in either situation.

Change-Id: I6862fe0828307a13b0004b192153747d85bb3a42
(cherry picked from commit 66e25aad35)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137173
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
This commit is contained in:
Michael Stahl 2022-07-14 17:57:18 +02:00
parent d996563ef1
commit 54aebc2c8f

View file

@ -10,6 +10,7 @@
#include <tools/fileutil.hxx> #include <tools/fileutil.hxx>
#if defined _WIN32 #if defined _WIN32
#include <osl/file.hxx> #include <osl/file.hxx>
#include <rtl/uri.hxx>
#include <o3tl/char16_t2wchar_t.hxx> #include <o3tl/char16_t2wchar_t.hxx>
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <Windows.h> #include <Windows.h>
@ -29,7 +30,11 @@ OUString UNCToDavURL(LPCWSTR sUNC)
bufURL = std::make_unique<wchar_t[]>(nSize); bufURL = std::make_unique<wchar_t[]>(nSize);
nResult = DavGetHTTPFromUNCPath(sUNC, bufURL.get(), &nSize); nResult = DavGetHTTPFromUNCPath(sUNC, bufURL.get(), &nSize);
} }
return nResult == ERROR_SUCCESS ? OUString(o3tl::toU(bufURL.get())) : OUString(); // looks like on different Windowses this may or may not be URL encoded?
return nResult == ERROR_SUCCESS
? ::rtl::Uri::encode(OUString(o3tl::toU(bufURL.get())), rtl_UriCharClassUric,
rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8)
: OUString();
} }
#endif #endif
} }