Skip to content
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: prevent removal of last character on no filename extension #120

Merged
merged 2 commits into from
Feb 3, 2023

Conversation

rexxars
Copy link
Member

@rexxars rexxars commented Feb 1, 2023

Fixes sanity-io/client#98

If a file is uploaded with an original filename that does not include an extension (.png or similar), the getFilenameWithoutExtension method will remove the last character of the filename. This is caused by using lastIndexOf('.'), which in the case of no . being present returns -1.

Theoretically you might still have odd results if you upload files with filename such as some.non.extension, which would result in some.non - but this is a bit of an edge case. Not sure what the best way of approach that would be - compare the extension (if present) with the mime type or generated asset filename?

Fixes sanity-io/client#98

If a file is uploaded with an original filename that does not include an extension (`.png` or similar), the `getFilenameWithoutExtension` method will remove the last character of the filename, because it uses the last index of `.`, which is not found, resulting in `-1`.
@robinpyon
Copy link
Collaborator

robinpyon commented Feb 3, 2023

Thanks @rexxars!

This highlighted a flaw with how this plugin displayed file extensions – the filename field input used the uploaded asset's extension and not originalFilename.

Conflating the resolved extension and the original filename in this way resulted in weird visual issues, especially when uploading files with mismatched or empty extensions.

That's now been simplified, we just render the filename in full and don't try and be cute with it!

@robinpyon robinpyon merged commit 3c0db14 into main Feb 3, 2023
@robinpyon robinpyon deleted the fix/filename-cut branch February 3, 2023 17:53
@github-actions
Copy link

github-actions bot commented Feb 3, 2023

🎉 This PR is included in version 2.0.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants