summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/url.c18
-rw-r--r--utils/url.h3
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);