Speed up downloads by combining multiple network connections in parallel
TypeScript bandwidth-aggregationcross-platformdesktop-appdownloaderdownloadmanagerlinuxmacosmulticonnectionparallel-downloadswindows
fix: keep spaces in an unquoted Content-Disposition filename (#183)
Rudy Mizrahi Celekli899d99b5a8d1
diff --git a/e2e/download.spec.ts b/e2e/download.spec.tsindex 1e82725..f711114 100644--- a/e2e/download.spec.ts+++ b/e2e/download.spec.ts@@ -183,6 +183,11 @@ test.describe('file names @smoke', () => {['path traversal is flattened', 'attachment; filename="../../evil.sh"', /^\.\._\.\._evil\.sh$/],['control characters are replaced', 'attachment; filename="a%0Ab.txt"', /^a_b\.txt$/],['an empty quoted filename falls back to the link', 'attachment; filename=""', /^test\.bin$/],+ [+ 'an unquoted filename keeps its spaces',+ 'attachment; filename=quarterly report.csv; size=10',+ /^quarterly report\.csv$/+ ],['an ISO-8859-1 filename* is decoded',"attachment; filename*=iso-8859-1'en'%A3%20rates.txt",diff --git a/src/main/download/contentDisposition.ts b/src/main/download/contentDisposition.tsindex c567a0f..2744db9 100644--- a/src/main/download/contentDisposition.ts+++ b/src/main/download/contentDisposition.ts@@ -75,12 +75,13 @@ export function decodeRfc2047Filename(name: string): string {export function parseContentDispositionFilename(disposition: string): string | null {// Read complete parameters, including quoted extension values, so a name inside- // another parameter cannot shadow filename. HTTP permits spaces/tabs around '='.+ // another parameter cannot shadow filename. HTTP permits spaces/tabs around '='. An unquoted+ // value runs to the next ';', as browsers read it: servers send filename=my report.pdf.const parameters = new Map<string, { raw: string; quoted: boolean }>()const extendedPattern = /^([a-zA-Z0-9_-]+)'[^']*'([^;\s]+)/let firstQuotedFilename: string | undefinedconst parameter =- /(?:^|;)[ \t]*([!#$%&'*+.^_`|~0-9a-z-]+)[ \t]*=[ \t]*(("(?:[^"\\]|\\.)*")|([^; \t]+))/gi+ /(?:^|;)[ \t]*([!#$%&'*+.^_`|~0-9a-z-]+)[ \t]*=[ \t]*(("(?:[^"\\]|\\.)*")|([^; \t](?:[^;]*[^; \t])?))/gifor (const match of disposition.matchAll(parameter)) {const key = match[1].toLowerCase()const quoted = match[3] !== undefined