From 21ce7e27a89c3f9c2fb4bc8bd59877dc2d8cd6b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sat, 8 Sep 2018 10:21:00 +0200 Subject: New upstream version 0.8.6 --- src/UriFile.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'src/UriFile.c') diff --git a/src/UriFile.c b/src/UriFile.c index 332f6a9..303ee49 100644 --- a/src/UriFile.c +++ b/src/UriFile.c @@ -104,7 +104,7 @@ static URI_INLINE int URI_FUNC(FilenameToUriString)(const URI_CHAR * filename, if ((input[0] == _UT('\0')) || (fromUnix && input[0] == _UT('/')) || (!fromUnix && input[0] == _UT('\\'))) { - /* Copy text after last seperator */ + /* Copy text after last separator */ if (lastSep + 1 < input) { if (!fromUnix && absolute && (firstSegment == URI_TRUE)) { /* Quick hack to not convert "C:" to "C%3A" */ @@ -148,13 +148,17 @@ static URI_INLINE int URI_FUNC(UriStringToFilename)(const URI_CHAR * uriString, } { - const UriBool file_two_slashes = - URI_STRNCMP(uriString, _UT("file://"), URI_STRLEN(_UT("file://"))) == 0; - const UriBool file_three_slashes = file_two_slashes + const UriBool file_unknown_slashes = + URI_STRNCMP(uriString, _UT("file:"), URI_STRLEN(_UT("file:"))) == 0; + const UriBool file_one_or_more_slashes = file_unknown_slashes + && (URI_STRNCMP(uriString, _UT("file:/"), URI_STRLEN(_UT("file:/"))) == 0); + const UriBool file_two_or_more_slashes = file_one_or_more_slashes + && (URI_STRNCMP(uriString, _UT("file://"), URI_STRLEN(_UT("file://"))) == 0); + const UriBool file_three_or_more_slashes = file_two_or_more_slashes && (URI_STRNCMP(uriString, _UT("file:///"), URI_STRLEN(_UT("file:///"))) == 0); - const size_t charsToSkip = file_two_slashes - ? file_three_slashes + const size_t charsToSkip = file_two_or_more_slashes + ? file_three_or_more_slashes ? toUnix /* file:///bin/bash */ ? URI_STRLEN(_UT("file://")) @@ -162,13 +166,21 @@ static URI_INLINE int URI_FUNC(UriStringToFilename)(const URI_CHAR * uriString, : URI_STRLEN(_UT("file:///")) /* file://Server01/Letter.txt */ : URI_STRLEN(_UT("file://")) - : 0; + : ((file_one_or_more_slashes && toUnix) + /* file:/bin/bash */ + /* https://tools.ietf.org/html/rfc8089#appendix-B */ + ? URI_STRLEN(_UT("file:")) + : ((! toUnix && file_unknown_slashes && ! file_one_or_more_slashes) + /* file:c:/path/to/file */ + /* https://tools.ietf.org/html/rfc8089#appendix-E.2 */ + ? URI_STRLEN(_UT("file:")) + : 0)); const size_t charsToCopy = URI_STRLEN(uriString + charsToSkip) + 1; const UriBool is_windows_network_with_authority = (toUnix == URI_FALSE) - && file_two_slashes - && ! file_three_slashes; + && file_two_or_more_slashes + && ! file_three_or_more_slashes; URI_CHAR * const unescape_target = is_windows_network_with_authority ? (filename + 2) -- cgit v1.2.3