diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2016-07-24 21:00:29 +0100 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2016-07-25 09:04:35 +0100 |
commit | a122b94efde125202388d135e36eb86e6d25d093 (patch) | |
tree | 73e9d34dbc6c7443c727b8d85ba2c1127e4ed1c3 /frontends/riscos | |
parent | 7bff70e7466dd80603922ba0dfdad1725cce41a6 (diff) | |
download | netsurf-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/riscos')
-rw-r--r-- | frontends/riscos/gui.c | 35 |
1 files changed, 19 insertions, 16 deletions
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; } |