Skip to content

Commit 48e5e99

Browse files
authored
fix(linux): improve download handler's default filename fallback logic (#1613)
1 parent 0f51d67 commit 48e5e99

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/webkitgtk/web_context.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,18 @@ impl WebContextExt for super::WebContext {
327327
.map(|(base, ext)| (base, format!(".{ext}")))
328328
.unwrap_or((suggested_filename, "".to_string()));
329329

330-
// for `data:` downloads, webkitgtk will suggest to use the raw data as the filename
331-
// for example `"data:attachment/text,sometext"` will result in `text,sometext`
330+
// For `data:` downloads, webkitgtk will suggest to use the raw data as the filename if the dev provided no name,
331+
// for example `"data:attachment/text,sometext"` will result in `text,sometext` but longer data URLs will
332+
// result in a cut-off filename, which makes it hard to predict reliably.
333+
// TODO: If this keeps causing problems, just remove it and use whatever file name webkitgtk suggests.
332334
if uri.starts_with("data:") {
333-
suggested_filename = "Unknown";
335+
if let Some((_, uri_stripped)) = uri.split_once('/') {
336+
if let Some((uri_stripped, _)) = uri_stripped.split_once(',') {
337+
if suggested_filename.starts_with(&format!("{uri_stripped},")) {
338+
suggested_filename = "Unknown";
339+
}
340+
}
341+
}
334342
}
335343

336344
download_destination.push(format!("{suggested_filename}{ext}"));

0 commit comments

Comments
 (0)