summaryrefslogtreecommitdiff
path: root/utils/nsurl/parse.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2018-09-26 09:39:09 +0100
committerVincent Sanders <vince@kyllikki.org>2018-09-26 17:21:33 +0100
commit9100fcb4095cf8858d4cd2c613bff69ceb4f71ec (patch)
treeaad9e4c8246f10ba5d12d8175bcec5fdc3b3f0dc /utils/nsurl/parse.c
parent83512a6ff529c7c5cb6315167cba1cf132e6a67a (diff)
downloadnetsurf-9100fcb4095cf8858d4cd2c613bff69ceb4f71ec.tar.gz
netsurf-9100fcb4095cf8858d4cd2c613bff69ceb4f71ec.tar.bz2
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
Diffstat (limited to 'utils/nsurl/parse.c')
-rw-r--r--utils/nsurl/parse.c20
1 files changed, 16 insertions, 4 deletions
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;
}
-