From 0d39c69763f7918fdd884516140e23b4eab51b10 Mon Sep 17 00:00:00 2001 From: John Tytgat Date: Wed, 2 Apr 2008 00:43:51 +0000 Subject: - riscos/gui.c(path_to_url): escape the characters which need to be escaped when converting the host path to file: URL. - utils/{url.c,url.h}(url_escape): * added parameter 'toskip' to specify number of input characters which need to be skipped in the escape process. This avoids extra malloc buffer juggling. * added parameter 'escexceptions' to specify the characters which need to be excluded from the escape process. Solves SF tracker ID 1910169. Note that when discname in path contains '/' characters (case: "file:///Sunfish#192.168.0.50::/home/joty.$/jo.html") or there is no discname specified at all (case "file:///HostFS:$/jo.htm"), you need an UnixLib fix as in http://www.riscos.info/websvn/listing.php?repname=gccsdk&path=%2Ftrunk%2Fgcc4%2F&rev=3395&sc=1 svn path=/trunk/netsurf/; revision=4069 --- utils/url.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'utils/url.c') diff --git a/utils/url.c b/utils/url.c index cc7a76215..b272a903a 100644 --- a/utils/url.c +++ b/utils/url.c @@ -871,17 +871,19 @@ 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 + * \param unescaped the unescaped string + * \param toskip number of bytes to skip in unescaped string + * \param sptoplus true iff spaces should be converted to + + * \param escexceptions NULL or a string of characters excluded to be escaped + * \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, bool sptoplus, - char **result) +url_func_result url_escape(const char *unescaped, size_t toskip, + bool sptoplus, const char *escexceptions, char **result) { - int len; - char *escaped, *d; + size_t len; + char *escaped, *d, *tmpres; const char *c; if (!unescaped || !result) @@ -890,21 +892,25 @@ url_func_result url_escape(const char *unescaped, bool sptoplus, *result = NULL; len = strlen(unescaped); + if (len < toskip) + return URL_FUNC_FAILED; + len -= toskip; escaped = malloc(len * 3 + 1); if (!escaped) return URL_FUNC_NOMEM; - for (c = unescaped, d = escaped; *c; c++) { + for (c = unescaped + toskip, d = escaped; *c; c++) { /* Check if we should escape this byte. * '~' is unreserved and should not be percent encoded, if * you believe the spec; however, leaving it unescaped * breaks a bunch of websites, so we escape it anyway. */ - if (!isascii(*c) || strchr(":/?#[]@" /* gen-delims */ - "!$&'()*+,;=" /* sub-delims */ - "<>%\"{}|\\^`~", /* others */ - *c) || - *c <= 0x20 || *c == 0x7f) { + if (!isascii(*c) + || (strchr(":/?#[]@" /* gen-delims */ + "!$&'()*+,;=" /* sub-delims */ + "<>%\"{}|\\^`~" /* others */, *c) + && (!escexceptions || !strchr(escexceptions, *c))) + || *c <= 0x20 || *c == 0x7f) { if (*c == 0x20 && sptoplus) { *d++ = '+'; } else { @@ -917,16 +923,17 @@ url_func_result url_escape(const char *unescaped, bool sptoplus, *d++ = *c; } } - *d++ = '\0'; - (*result) = malloc(d - escaped); - if (!(*result)) { + tmpres = malloc(d - escaped + toskip); + if (!tmpres) { free(escaped); return URL_FUNC_NOMEM; } - memcpy((*result), escaped, d - escaped); + memcpy(tmpres, unescaped, toskip); + memcpy(tmpres + toskip, escaped, d - escaped); + *result = tmpres; free(escaped); -- cgit v1.2.3