mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-23 10:52:07 +03:00
Fix bug #3238151: reinstate filename sanitisation and extension stripping
svn path=/trunk/netsurf/; revision=12127
This commit is contained in:
parent
237a62a9e7
commit
8ea109784c
@ -228,7 +228,7 @@ struct gui_download_window *gui_download_window_create(download_context *ctx,
|
|||||||
url_func_result res;
|
url_func_result res;
|
||||||
char *local_path;
|
char *local_path;
|
||||||
utf8_convert_ret err;
|
utf8_convert_ret err;
|
||||||
size_t i;
|
size_t i, last_dot;
|
||||||
|
|
||||||
dw = malloc(sizeof *dw);
|
dw = malloc(sizeof *dw);
|
||||||
if (!dw) {
|
if (!dw) {
|
||||||
@ -354,9 +354,18 @@ struct gui_download_window *gui_download_window_create(download_context *ctx,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; filename[i] != '\0'; i++)
|
for (i = 0, last_dot = (size_t) -1; filename[i] != '\0'; i++) {
|
||||||
if (filename[i] == '.')
|
const char c = filename[i];
|
||||||
|
|
||||||
|
if (c == '.') {
|
||||||
|
last_dot = i;
|
||||||
filename[i] = '/';
|
filename[i] = '/';
|
||||||
|
} else if (c <= ' ' || strchr(":*#$&@^%\\", c) != NULL)
|
||||||
|
filename[i] = '_';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (option_strip_extensions && last_dot != (size_t) -1)
|
||||||
|
filename[last_dot] = '\0';
|
||||||
|
|
||||||
if (download_dir != NULL && strlen(download_dir) > 0)
|
if (download_dir != NULL && strlen(download_dir) > 0)
|
||||||
snprintf(dw->path, RO_DOWNLOAD_MAX_PATH_LEN, "%s.%s",
|
snprintf(dw->path, RO_DOWNLOAD_MAX_PATH_LEN, "%s.%s",
|
||||||
|
Loading…
Reference in New Issue
Block a user