Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
webui: fix the attachment; filename encoding, fixes #2086
  • Loading branch information
perexg committed Jun 2, 2015
1 parent 057a006 commit 2fdfe48
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/webui/webui.c
Expand Up @@ -1146,18 +1146,20 @@ page_play(http_connection_t *hc, const char *remain, void *opaque)
static int
page_dvrfile(http_connection_t *hc, const char *remain, void *opaque)
{
int fd, i, ret;
int fd, ret;
struct stat st;
const char *content = NULL, *range, *filename;
dvr_entry_t *de;
char *fname;
char *basename;
char *str;
char range_buf[255];
char disposition[256];
off_t content_len, chunk;
intmax_t file_start, file_end;
void *tcp_id;
th_subscription_t *sub;
htsbuf_queue_t q;
#if defined(PLATFORM_LINUX)
ssize_t r;
#elif defined(PLATFORM_FREEBSD) || defined(PLATFORM_DARWIN)
Expand Down Expand Up @@ -1196,13 +1198,12 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque)
basename = strrchr(fname, '/');
if (basename) {
basename++; /* Skip '/' */
snprintf(disposition, sizeof(disposition), "attachment; filename=\"%s\"", basename);
// Ensure there are no " characters in the filename.
i = strlen(disposition)-2;
while (i > 21) {
if (disposition[i] == '"') { disposition[i] = '_'; }
i--;
}
htsbuf_queue_init(&q, 0);
htsbuf_append_and_escape_url(&q, basename);
str = htsbuf_to_string(&q);
snprintf(disposition, sizeof(disposition), "attachment; filename=\"%s\"", str);
htsbuf_queue_flush(&q);
free(str);
} else {
disposition[0] = 0;
}
Expand Down

0 comments on commit 2fdfe48

Please sign in to comment.