diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2019-02-06 10:20:16 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-02-06 11:18:27 +0100 |
commit | f90e26b6313a2a7e492337f5957e49f5a512e5e7 (patch) | |
tree | 2cce2b81956046df06407caccac81c972be57667 /sal/osl | |
parent | 48f1451407443450e49b1253e95671d9513021b8 (diff) |
tdf#107461: For Unix-like OS, support file://<hostname>/... URLs
...where <hostname> matches whatever osl_getLocalHostname reports. (And, for
simplicity, don't support variations where e.g. one of the two FQDNs has an
optional final dot while the other has not.)
(It is not clear to me whether a similar change should also be done for the
Windows-specific code in sal/osl/w32/file_url.cxx. On Windows, file URLs with a
host component are generally interpreted as UNC pathnames, and in some local
test on a Windows 8 machine whose hostname is reported as "win8", passing a URL
like <file://win8/Users/me/Documents/...> (i.e., without a C: drive letter) to
LO already worked to access files on the default drive C: at least.)
Change-Id: I7a69b6d4ca76a71223def7b90d7c3b8b731ee86d
Reviewed-on: https://gerrit.libreoffice.org/67437
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sal/osl')
-rw-r--r-- | sal/osl/unx/file_url.cxx | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/sal/osl/unx/file_url.cxx b/sal/osl/unx/file_url.cxx index 24fa04c7bfa6..0661975926fe 100644 --- a/sal/osl/unx/file_url.cxx +++ b/sal/osl/unx/file_url.cxx @@ -30,6 +30,7 @@ #include <osl/file.hxx> #include <osl/security.hxx> +#include <osl/socket.h> #include <osl/diagnose.h> #include <osl/thread.h> #include <osl/process.h> @@ -136,7 +137,9 @@ oslFileError getSystemPathFromFileUrl( // Handle query or fragment: if (url.indexOf('?', i) != -1 || url.indexOf('#', i) != -1) return osl_File_E_INVAL; - // Handle authority: + // Handle authority, supporting a host of "localhost", "127.0.0.1", or the exact value (e.g., + // not supporting an additional final dot, for simplicity) reported by osl_getLocalHostname + // (and, in each case, ignoring case of ASCII letters): if (url.getLength() - i >= 2 && url[i] == '/' && url[i + 1] == '/') { i += 2; @@ -153,7 +156,14 @@ oslFileError getSystemPathFromFileUrl( RTL_CONSTASCII_STRINGPARAM("127.0.0.1")) != 0)) { - return osl_File_E_INVAL; + OUString hostname; + if (osl_getLocalHostname(&hostname.pData) != osl_Socket_Ok + || (rtl_ustr_compareIgnoreAsciiCase_WithLength( + url.pData->buffer + i, j - i, hostname.getStr(), hostname.getLength()) + != 0)) + { + return osl_File_E_INVAL; + } } i = j; } |