Author: mmu_man
Date: Thu Aug 12 08:33:53 2010
New Revision: 10688
URL:
http://source.netsurf-browser.org?rev=10688&view=rev
Log:
Copy over the gtk implementation of url_to_path/path_to_url(). This fixes getting the mime
type of local files.
Modified:
trunk/netsurf/beos/beos_gui.cpp
Modified: trunk/netsurf/beos/beos_gui.cpp
URL:
http://source.netsurf-browser.org/trunk/netsurf/beos/beos_gui.cpp?rev=106...
==============================================================================
--- trunk/netsurf/beos/beos_gui.cpp (original)
+++ trunk/netsurf/beos/beos_gui.cpp Thu Aug 12 08:33:53 2010
@@ -1165,17 +1165,32 @@
char *path_to_url(const char *path)
{
- char *r = (char *)malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1);
-
- strcpy(r, FILE_SCHEME_PREFIX);
- strcat(r, path);
-
- return r;
+ int urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1;
+ char *url = (char *)malloc(urllen);
+
+ if (url == NULL) {
+ return NULL;
+ }
+
+ if (*path == '/') {
+ path++; /* file: paths are already absolute */
+ }
+
+ 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)