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

Waffle crashes when URL has no path #106

Open
woylie opened this issue Nov 15, 2022 · 2 comments
Open

Waffle crashes when URL has no path #106

woylie opened this issue Nov 15, 2022 · 2 comments

Comments

@woylie
Copy link

woylie commented Nov 15, 2022

If a URL is passed to Waffle (e.g. through cast_attachments), and the URL has no path (e.g. https://google.com), Waffle causes an exception, because it passes the path of the parsed URI to Path.basename/1 without checking for nil or / first.

filename = uri.path |> Path.basename() |> URI.decode()

** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1
    (elixir 1.14.2) IO.chardata_to_string(nil)
    (elixir 1.14.2) lib/path.ex:383: Path.basename/1
    (waffle 1.1.6) lib/waffle/file.ex:18: Waffle.File.new/2
    (waffle 1.1.6) lib/waffle/actions/store.ex:54: Waffle.Actions.Store.store/2
    (waffle_ecto 0.0.11) lib/waffle_ecto/type.ex:21: Waffle.Ecto.Type.cast/2

Waffle should handle this case gracefully.

@fastjames
Copy link
Contributor

@woylie would this issue also cover URLs with a non-traditional "filename" such as https://google.com/test/.jpg ? I have encountered a service that provides URLs in this form, and I suspect that I will need to refactor some of the filename handling code in waffle to deal with that case.

@woylie
Copy link
Author

woylie commented Feb 22, 2024

@woylie would this issue also cover URLs with a non-traditional "filename" such as https://google.com/test/.jpg ? I have encountered a service that provides URLs in this form, and I suspect that I will need to refactor some of the filename handling code in waffle to deal with that case.

I linked the relevant code. If you run it with a URL in that format, you get:

iex> URI.parse("https://google.com/test/.jpg").path |> Path.basename() |> URI.decode()
".jpg"

So it doesn't crash at least.

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

No branches or pull requests

2 participants