Bug 170674 - File API constructor filename ignored
Summary: File API constructor filename ignored
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 10
Hardware: Unspecified iOS 10
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-04-10 06:00 PDT by Dániel Stein
Modified: 2018-05-24 08:33 PDT (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dániel Stein 2017-04-10 06:00:22 PDT
Trying to download a file with a given filename from a blob. Opening a webpage containing the following script shows a file download screen with "Unknown" as the filename instead of the parameter.


```
window.location = URL.createObjectURL(new File(["content"], "filename.txt", {type: "application/octet-stream", lastModified: new Date()}));
```

OS: iOS 10.3.2
Device: iPad mini 3
Comment 1 Radar WebKit Bug Importer 2017-04-10 07:17:15 PDT
<rdar://problem/31531994>
Comment 2 ebrommers 2018-05-23 14:06:29 PDT
Related issue, so I'll add it here instead of creating a new issue. 

When you create a File object using a string value (iOS 11.3), that value ends up populating the name property instead of the name passed in.


```
var myFile = new File(["Something wrong here"], "myFileName", {type: "text/plain"});
```

looking at myFile.name in the debugger gives an array value with "Something wrong here" as element[0]; the value for "myFileName" ends up in another attribute "localURL".
Comment 3 ebrommers 2018-05-23 16:32:50 PDT
(In reply to ebrommers from comment #2)
> Related issue, so I'll add it here instead of creating a new issue. 
> 
> When you create a File object using a string value (iOS 11.3), that value
> ends up populating the name property instead of the name passed in.
> 
> 
> ```
> var myFile = new File(["Something wrong here"], "myFileName", {type:
> "text/plain"});
> ```
> 
> looking at myFile.name in the debugger gives an array value with "Something
> wrong here" as element[0]; the value for "myFileName" ends up in another
> attribute "localURL".

Update: it looks like passing in a blob instead of a string value does the same thing. Somewhere File.name is getting assigned the value of the first parameter in the constructor (which should be the contents of the file, if I'm reading the spec correctly).
Comment 4 Chris Dumez 2018-05-23 16:36:02 PDT
> (new File(["Something wrong here"], "myFileName", {type: "text/plain"})).name
< "myFileName"

Seems to work fine here on Safari Tech Preview.
Comment 5 Chris Dumez 2018-05-23 16:37:58 PDT
(In reply to Chris Dumez from comment #4)
> > (new File(["Something wrong here"], "myFileName", {type: "text/plain"})).name
> < "myFileName"
> 
> Seems to work fine here on Safari Tech Preview.

Also works for me on iOS.
Comment 6 ebrommers 2018-05-24 06:50:31 PDT
> (new File(["Something wrong here"], "myFileName", {type: "text/plain"})).name

< ["Something wrong here"] (1)

iOS 11.3 (15E217) / running on iPhone SE in simulator -- if that makes a difference.
Comment 7 ebrommers 2018-05-24 07:01:15 PDT
Ooh, interesting -- Plain-ol' Safari on my MacBook Pro (Version 11.1 (13605.1.33.1.4)) returns the correct value. 

So... Xcode emulation or iOS Safari weirdness?
Comment 8 Chris Dumez 2018-05-24 07:17:57 PDT
(In reply to ebrommers from comment #7)
> Ooh, interesting -- Plain-ol' Safari on my MacBook Pro (Version 11.1
> (13605.1.33.1.4)) returns the correct value. 
> 
> So... Xcode emulation or iOS Safari 

I tried both MacOS and iOS device. I did not try iOS simulator. Any behavior difference would be unexpected though.
Comment 9 ebrommers 2018-05-24 08:33:26 PDT
Thanks, Chris.

Poking around a little further, it looks like this behavior is due to an older JS runtime (I'm developing a Cordova app, and this is in the default UIWebView rather than in the WKWebView). So... probably best to leave this in the "just in case someone else in Cordova-land gets stuck" pile.