From 4cb2657d191d626e3ddb37166fa591ce877d0434 Mon Sep 17 00:00:00 2001 From: François Revel Date: Thu, 12 Aug 2010 13:33:53 +0000 Subject: Copy over the gtk implementation of url_to_path/path_to_url(). This fixes getting the mime type of local files. svn path=/trunk/netsurf/; revision=10688 --- beos/beos_gui.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'beos/beos_gui.cpp') diff --git a/beos/beos_gui.cpp b/beos/beos_gui.cpp index 768ae7680..d8cb4bbb2 100644 --- a/beos/beos_gui.cpp +++ b/beos/beos_gui.cpp @@ -1165,17 +1165,32 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, char *path_to_url(const char *path) { - char *r = (char *)malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1); + int urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; + char *url = (char *)malloc(urllen); - strcpy(r, FILE_SCHEME_PREFIX); - strcat(r, path); + if (url == NULL) { + return NULL; + } + + if (*path == '/') { + path++; /* file: paths are already absolute */ + } - return r; + snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path); + + return url; } char *url_to_path(const char *url) { - return strdup(url + FILE_SCHEME_PREFIX_LEN); + char *url_path = curl_unescape(url, 0); + char *path; + + /* return the absolute path including leading / */ + path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1)); + curl_free(url_path); + + return path; } bool cookies_update(const char *domain, const struct cookie_data *data) -- cgit v1.2.3