-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug where formatId is set to application/vnd.ms-excel for csvs #930
Conversation
…th excel mime type
Heya @dmullen17 - Thanks for the PR. I certainly understand your logic for creating |
@csjx thanks for the review! I updated Additional comments / explanations:
|
Hey Dom - I looked at your code yesterday and it's looking good! Have you done some testing? It'd be a good test to upload like a hundred different file types in the editor and test whether the expected |
@laurenwalker thanks for looking over it! I tested it with ~ 20 common file types - I can test the rest of the DataOne formats as well. Is there somewhere I could add a unit test? I can also store a folder that contains a sample file of each Dataone format somewhere useful (if something similar already exists let me know!) |
We're developing unit tests on the |
hey @laurenwalker @csjx when one of you has a second can I get your thoughts on the tests I'm writing for
The test is working as expected, it actually helped me uncover some other file formats that aren't being set correctly, like Here's a fiddle of the tests so far. If you want to run them the best way I've found is by: adding a Any feedback would be really appreciated! |
I've been working on getting all the tests working with access to the MetacatUI global object and all it's attributes. Once that is done, could you submit a separate pull request with your test and I'll take a look? I'll let you know here when that code is checked in. |
This issue popped up again with our OPC hosted repository. Related to #560. |
The upshot I think is that Microsoft Excel doesn't change the OS-level metadata when it exports a CSV file. When someone then uploads a CSV using the editor, the |
Yeah, we could make special exceptions for Excel formatids to trust the .csv extension |
Have you seen that under some combination of variables? It doesn't happen here on a CSV I saved with Excel:
That's just a UTF-8 BOM followed by my data and Chrome/Firefox/Safari reports it as |
I've only seen this bug happen on Windows. |
Gotcha. I was just curious so I checked: It turns out that Chrome and other browsers are picking this up from |
Thanks @dmullen17 for your work on this. It's finally merged in! |
Bug fix where the editor sets the
formatId
toapplication/vnd.ms-excel
for csv files with their mime type set as excel (only occurs for excel-exported csvs in windows).I decided to add a new method because
DataONEObject.getFormatId
returns the firstformatId
that matches an object's mediatype. The body ofsanitizeFormatId
would need to be inserted before that first return, so an additional method seemed cleaner.Some possible changes:
I grabbed this block of code to extract the extension from the fileName and modified it so it only calls
this.get("fileName")
once, but I can revert that to maintain consistency if needed.This block could be removed without affecting the function, but I thought it would improve the speed to skip all non
application/vnd.ms-excel
files.