diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2006-09-19 10:08:33 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2006-09-19 10:08:33 +0000 |
commit | 4b09b7b8a0a4dc4768985ce74b2872ea9fba0684 (patch) | |
tree | f84b58c0134c49a9a7989d5c8d62b1865dcebf37 /utils | |
parent | a1b60054976684f1e9138de0714351610319676b (diff) | |
download | netsurf-4b09b7b8a0a4dc4768985ce74b2872ea9fba0684.tar.gz netsurf-4b09b7b8a0a4dc4768985ce74b2872ea9fba0684.tar.bz2 |
Correcly encode spaces for url-encoded form submission.
svn path=/trunk/netsurf/; revision=2960
Diffstat (limited to 'utils')
-rw-r--r-- | utils/url.c | 18 | ||||
-rw-r--r-- | utils/url.h | 3 |
2 files changed, 14 insertions, 7 deletions
diff --git a/utils/url.c b/utils/url.c index 2ee7b2d5f..0d3605d2e 100644 --- a/utils/url.c +++ b/utils/url.c @@ -236,8 +236,8 @@ url_func_result url_join(const char *rel, const char *base, char **result) assert(base); assert(rel); - - + + /* break down the relative URL (not cached, corruptable) */ status = url_get_components(rel, (struct url_components *)&rel_components); @@ -761,11 +761,13 @@ no_path: * Escape a string suitable for inclusion in an URL. * * \param unescaped the unescaped string + * \param sptoplus true iff spaces should be converted to + * \param result pointer to pointer to buffer to hold escaped string * \return URL_FUNC_OK on success */ -url_func_result url_escape(const char *unescaped, char **result) +url_func_result url_escape(const char *unescaped, bool sptoplus, + char **result) { int len; char *escaped, *d; @@ -786,9 +788,13 @@ url_func_result url_escape(const char *unescaped, char **result) if (!isascii(*c) || strchr(";/?:@&=+$," "<>#%\"{}|\\^[]`", *c) || *c <= 0x20 || *c == 0x7f) { - *d++ = '%'; - *d++ = "0123456789ABCDEF"[((*c >> 4) & 0xf)]; - *d++ = "0123456789ABCDEF"[(*c & 0xf)]; + if (*c == 0x20 && sptoplus) + *d++ = '+'; + else { + *d++ = '%'; + *d++ = "0123456789ABCDEF"[((*c >> 4) & 0xf)]; + *d++ = "0123456789ABCDEF"[(*c & 0xf)]; + } } else { /* unreserved characters: [a-zA-Z0-9-_.!~*'()] */ diff --git a/utils/url.h b/utils/url.h index d61526d66..5877b9e9a 100644 --- a/utils/url.h +++ b/utils/url.h @@ -35,7 +35,8 @@ url_func_result url_host(const char *url, char **result); url_func_result url_scheme(const char *url, char **result); url_func_result url_nice(const char *url, char **result, bool remove_extensions); -url_func_result url_escape(const char *unescaped, char **result); +url_func_result url_escape(const char *unescaped, bool sptoplus, + char **result); url_func_result url_canonical_root(const char *url, char **result); url_func_result url_parent(const char *url, char **result); url_func_result url_plq(const char *url, char **result); |