From 9100fcb4095cf8858d4cd2c613bff69ceb4f71ec Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 26 Sep 2018 09:39:09 +0100 Subject: improve nsurl query handling. Alter the handling of query values within nsurl to be like fragments. This ensures callers never have to care about the query punctuation, e.g. the question mark This also means the strings generated will no longer have trailing question marks which now conforms to behaviour in whatwg url spec on url serializing in section 4.5 --- utils/nsurl/parse.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'utils/nsurl/parse.c') diff --git a/utils/nsurl/parse.c b/utils/nsurl/parse.c index 3e3c52165..3b8816dd8 100644 --- a/utils/nsurl/parse.c +++ b/utils/nsurl/parse.c @@ -344,7 +344,7 @@ static void nsurl__get_string_markers(const char * const url_s, * and in the case of mailto: when we assume there is an authority. */ if ((*pos == '/' && *(pos + 1) == '/') || - (is_http && ((joining && *pos == '/') || + (is_http && ((joining && *pos == '/') || (joining == false && marker.scheme_end != marker.start))) || marker.scheme_type == NSURL_SCHEME_MAILTO) { @@ -577,7 +577,7 @@ static size_t nsurl__remove_dot_segments(char *path, char *output) /* Copy up to but not including next '/' */ while ((*path_pos != '/') && (*path_pos != '\0')) - *output_pos++ = *path_pos++; + *output_pos++ = *path_pos++; } return output_pos - output; @@ -671,7 +671,9 @@ static nserror nsurl__create_from_section(const char * const url_s, break; case URL_QUERY: - start = pegs->query; + start = (*(url_s + pegs->query) != '?') ? + pegs->query : + pegs->query + 1; end = pegs->fragment; break; @@ -1085,6 +1087,15 @@ static void nsurl__get_string_data(const struct nsurl_components *url, *url_l += SLEN("@"); } + /* spanned query question mark */ + if ((flags & ~(NSURL_F_QUERY | NSURL_F_FRAGMENT)) && + (flags & NSURL_F_QUERY)) { + flags |= NSURL_F_QUERY_PUNCTUATION; + + *url_l += SLEN("?"); + } + + /* spanned fragment hash mark */ if ((flags & ~NSURL_F_FRAGMENT) && (flags & NSURL_F_FRAGMENT)) { flags |= NSURL_F_FRAGMENT_PUNCTUATION; @@ -1158,6 +1169,8 @@ static void nsurl__get_string(const struct nsurl_components *url, char *url_s, } if (flags & NSURL_F_QUERY) { + if (flags & NSURL_F_QUERY_PUNCTUATION) + *(pos++) = '?'; memcpy(pos, lwc_string_data(url->query), l->query); pos += l->query; } @@ -1557,4 +1570,3 @@ nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined) return NSERROR_OK; } - -- cgit v1.2.3