diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/UriFile.c | 30 | ||||
-rw-r--r-- | src/UriParse.c | 1 | ||||
-rw-r--r-- | src/UriRecompose.c | 2 | ||||
-rw-r--r-- | src/UriShorten.c | 24 |
4 files changed, 29 insertions, 28 deletions
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) diff --git a/src/UriParse.c b/src/UriParse.c index 5eee16d..e087753 100644 --- a/src/UriParse.c +++ b/src/UriParse.c @@ -941,6 +941,7 @@ static const URI_CHAR * URI_FUNC(ParseMustBeSegmentNzNc)(URI_TYPE(ParserState) * */ static URI_INLINE const URI_CHAR * URI_FUNC(ParseOwnHost)(URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast) { if (first >= afterLast) { + state->uri->hostText.afterLast = afterLast; /* HOST END */ return afterLast; } diff --git a/src/UriRecompose.c b/src/UriRecompose.c index 9678aac..2705cf1 100644 --- a/src/UriRecompose.c +++ b/src/UriRecompose.c @@ -105,7 +105,7 @@ static URI_INLINE int URI_FUNC(ToStringEngine)(URI_CHAR * dest, } return URI_ERROR_TOSTRING_TOO_LONG; } - maxChars--; /* So we don't have to substract 1 for '\0' all the time */ + maxChars--; /* So we don't have to subtract 1 for '\0' all the time */ /* [01/19] result = "" */ if (dest != NULL) { diff --git a/src/UriShorten.c b/src/UriShorten.c index 0145f68..e7f6df4 100644 --- a/src/UriShorten.c +++ b/src/UriShorten.c @@ -111,22 +111,12 @@ static URI_INLINE UriBool URI_FUNC(EqualsAuthority)(const URI_TYPE(Uri) * first, /* IPvFuture */ if (first->hostData.ipFuture.first != NULL) { return ((second->hostData.ipFuture.first != NULL) - && !URI_STRNCMP(first->hostData.ipFuture.first, - second->hostData.ipFuture.first, - first->hostData.ipFuture.afterLast - - first->hostData.ipFuture.first)) - ? URI_TRUE : URI_FALSE; + && !URI_FUNC(CompareRange)(&first->hostData.ipFuture, + &second->hostData.ipFuture)) ? URI_TRUE : URI_FALSE; } - if (first->hostText.first != NULL) { - return ((second->hostText.first != NULL) - && !URI_STRNCMP(first->hostText.first, - second->hostText.first, - first->hostText.afterLast - - first->hostText.first)) ? URI_TRUE : URI_FALSE; - } - - return (second->hostText.first == NULL); + return !URI_FUNC(CompareRange)(&first->hostText, &second->hostText) + ? URI_TRUE : URI_FALSE; } @@ -155,8 +145,7 @@ static int URI_FUNC(RemoveBaseUriImpl)(URI_TYPE(Uri) * dest, } /* [01/50] if (A.scheme != Base.scheme) then */ - if (URI_STRNCMP(absSource->scheme.first, absBase->scheme.first, - absSource->scheme.afterLast - absSource->scheme.first)) { + if (URI_FUNC(CompareRange)(&absSource->scheme, &absBase->scheme)) { /* [02/50] T.scheme = A.scheme; */ dest->scheme = absSource->scheme; /* [03/50] T.authority = A.authority; */ @@ -216,8 +205,7 @@ static int URI_FUNC(RemoveBaseUriImpl)(URI_TYPE(Uri) * dest, dest->absolutePath = URI_FALSE; /* [22/50] while (first(A.path) == first(Base.path)) do */ while ((sourceSeg != NULL) && (baseSeg != NULL) - && !URI_STRNCMP(sourceSeg->text.first, baseSeg->text.first, - sourceSeg->text.afterLast - sourceSeg->text.first) + && !URI_FUNC(CompareRange)(&sourceSeg->text, &baseSeg->text) && !((sourceSeg->text.first == sourceSeg->text.afterLast) && ((sourceSeg->next == NULL) != (baseSeg->next == NULL)))) { /* [23/50] A.path++; */ |