8000 bug in casting values to integer or float · Issue #70 · kbrw/sweet_xml · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
bug in casting values to integer or float #70
Open
@ckruse

Description

@ckruse

Hi,

I'm trying to parse a XML feed with sweet_xml. Due to the nature of the web ;-) there may be feeds that are invalid. In this case I had a feed with a missing element, and thus the XPath expression could not be resolved;

However, this clause matches for an integer cast in this case:

defp to_cast(value, :integer, _is_opt?), do: String.to_integer(to_string(value))

This leads to an argument error because String.to_integer gets called with an empty string:

** (ArgumentError) argument error
    :erlang.binary_to_integer("")
    (sweet_xml) lib/sweet_xml.ex:665: SweetXml.to_cast/3
    (sweet_xml) lib/sweet_xml.ex:441: SweetXml.xpath/2
    (sweet_xml) lib/sweet_xml.ex:531: anonymous fn/3 in SweetXml.xmap/3
    (elixir) lib/map.ex:791: Map.get_and_update/3
    (sweet_xml) lib/sweet_xml.ex:531: SweetXml.xmap/3
    (sweet_xml) lib/sweet_xml.ex:530: SweetXml.xmap/3

Is this a thing you will want to fix? All other XPath expressions don't lead to a crash, so it seems like a bug to me. On the other hand, the input is invalid; what's the right thing to do here?

To fix this one could add another function clause for empty strings in casts to float or integer; but then it would fail if the input string is not a number.

That's why I didn't create a pull request, I'm really not sure what your thoughts are about this.

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

      0