Skip to content

armgit / plexo

Public Imported from GitHub
0

Speed up downloads by combining multiple network connections in parallel

fix: name the file from the link when Content-Disposition has filename="" (#181)

Rudy Mizrahi Celekli3f4c90874f10
diff --git a/e2e/download.spec.ts b/e2e/download.spec.ts
index a5cbbf7..1e82725 100644
--- a/e2e/download.spec.ts
+++ b/e2e/download.spec.ts
@@ -182,6 +182,7 @@ 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 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.ts
index 4349c7d..c567a0f 100644
--- a/src/main/download/contentDisposition.ts
+++ b/src/main/download/contentDisposition.ts
@@ -130,8 +130,8 @@ export function parseContentDispositionFilename(disposition: string): string | n
return decodeRfc2047Filename(decoded)
}
- // Unquoted token fallback
- const tokenMatch = filename ? [filename.raw, filename.raw] : null
+ // Unquoted token fallback. A quoted one that got here was empty: the quotes aren't a name.
+ const tokenMatch = filename && !filename.quoted ? [filename.raw, filename.raw] : null
if (tokenMatch?.[1]) {
let decoded: string
try {