summaryrefslogtreecommitdiff
path: root/frontends
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2016-07-24 21:00:29 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2016-07-25 09:04:35 +0100
commita122b94efde125202388d135e36eb86e6d25d093 (patch)
tree73e9d34dbc6c7443c727b8d85ba2c1127e4ed1c3 /frontends
parent7bff70e7466dd80603922ba0dfdad1725cce41a6 (diff)
downloadnetsurf-a122b94efde125202388d135e36eb86e6d25d093.tar.gz
netsurf-a122b94efde125202388d135e36eb86e6d25d093.tar.bz2
URL escape: Simplify to avoid unnecessary allocation.
This removes the toskip parameter, which was only used by the RISC OS front end. The toskip param was used to skip 8 characters which did not need to be escaped from the start of the URL. The RISC OS front end now orders the steps of its URL construction to avoid the need for this.
Diffstat (limited to 'frontends')
-rw-r--r--frontends/atari/file.c2
-rw-r--r--frontends/riscos/gui.c35
2 files changed, 20 insertions, 17 deletions
diff --git a/frontends/atari/file.c b/frontends/atari/file.c
index 3816e476d..235d8240f 100644
--- a/frontends/atari/file.c
+++ b/frontends/atari/file.c
@@ -193,7 +193,7 @@ static nserror atari_path_to_nsurl(const char *path, struct nsurl **url_out)
}
/* escape the path so it can be placed in a url */
- ret = url_escape(path, 0, false, "/", &escpath);
+ ret = url_escape(path, false, "/", &escpath);
if (ret != NSERROR_OK) {
return ret;
}
diff --git a/frontends/riscos/gui.c b/frontends/riscos/gui.c
index 72eeb6282..7c5216462 100644
--- a/frontends/riscos/gui.c
+++ b/frontends/riscos/gui.c
@@ -1405,7 +1405,7 @@ static nserror ro_path_to_nsurl(const char *path, struct nsurl **url_out)
int spare;
char *canonical_path; /* canonicalised RISC OS path */
char *unix_path; /* unix path */
- char *escurl;
+ char *escaped_path;
os_error *error;
nserror ret;
int urllen;
@@ -1443,31 +1443,34 @@ static nserror ro_path_to_nsurl(const char *path, struct nsurl **url_out)
}
free(canonical_path);
- /* convert the unix path into a url */
- urllen = strlen(unix_path) + FILE_SCHEME_PREFIX_LEN + 1;
+ /* url escape the unix path */
+ ret = url_escape(unix_path, false, "/", &escaped_path);
+ if (ret != NSERROR_OK) {
+ free(unix_path);
+ return ret;
+ }
+ free(unix_path);
+
+ /* convert the escaped unix path into a url */
+ urllen = strlen(escaped_path) + FILE_SCHEME_PREFIX_LEN + 1;
url = malloc(urllen);
if (url == NULL) {
LOG("Unable to allocate url");
- free(unix_path);
+ free(escaped_path);
return NSERROR_NOMEM;
}
- if (*unix_path == '/') {
- snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, unix_path + 1);
+ if (*escaped_path == '/') {
+ snprintf(url, urllen, "%s%s",
+ FILE_SCHEME_PREFIX, escaped_path + 1);
} else {
- snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, unix_path);
+ snprintf(url, urllen, "%s%s",
+ FILE_SCHEME_PREFIX, escaped_path);
}
- free(unix_path);
+ free(escaped_path);
- /* We don't want '/' to be escaped. */
- ret = url_escape(url, FILE_SCHEME_PREFIX_LEN, false, "/", &escurl);
+ ret = nsurl_create(url, url_out);
free(url);
- if (ret != NSERROR_OK) {
- return ret;
- }
-
- ret = nsurl_create(escurl, url_out);
- free(escurl);
return ret;
}