File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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}" ) ) ;
You can’t perform that action at this time.
0 commit comments