jsonkenl / xlsxir

Xlsx parser for the Elixir language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Validation of xlsx file based on content_type (or someother attribute) than file_path

pikender opened this issue Β· comments

Usecase

When using Phoenix and integrating parsing of xlsx files, there could be a possibility of passing Plug.Upload file_path for parsing but it bails out due to xlsx file_extension.

Even though the file is a valid xlsx, it fails 😒

Bypassing the file_path check, correctly parses and returns valid data

I don't have much of backgroud in xlsx parsing stuff but curious if we can shift to more robust than file_extension as I can change the extension of any file and make it pass through validation check and a valid file gets blocked due to it.

Let me know if I can be of any help in fixing it. I will need some guidance though πŸ˜‰

I hadn't thought about a case where the temp file from Plug.Upload wouldn't have the proper extension. Good catch! I'll figure out a better way to validate the file.

Ok, @pikender I changed the way the validation works. It's now utilizing a function in the Erlang :zip library to verify that the requested worksheet is present in the file. It doesn't matter if the extension is not .xlsx. Would you mind testing out the change for you use case and let me know how it goes? I'll wait to hear back before publishing the fix on Hex. Thanks!

@kennellroxco sure πŸ‘

Can we return error tuple instead of failing with MatchError ??

There is no violation of Let it crash principle also as it's a validation which should be informed to invoking party for making corrections.

We need to change the error hinting about worksheet(index) might be missing

{:error, "Invalid path. Currently only .xlsx file types are supported."}

What are your thoughts ?

@pikender I made the changes you requested. Please take it for a spin and let me know your thoughts. Thanks again!

@kennellroxco it's awesome now. Tested with xml, csv, xls and xlsx. Rightly informed "Invalid File Type" for other than xlsx and parsed xlsx correctly 😊

Looks good and Thanks πŸ‘

Awesome! Closing issue and publishing update on Hex. Thanks for the help!

Thanks @kennellroxco for superfast reply and incorporating changes fast πŸ’― ❀️ πŸ‘