Skip to content

Waffle crashes when URL has no path #106

@woylie

Description

@woylie

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions