Skip to content

Parser.int and Parser.float handle leading Zeros unexpectedly #45

@maxmunzel

Description

@maxmunzel

Hi everyone,

I stumbled upon odd behaviour regarding leading zeros:

Observed

> Parser.run Parser.int "0123"
Ok 0 : Result (List Parser.DeadEnd) Int
> Parser.run Parser.float "0123"
Ok 0 : Result (List Parser.DeadEnd) Float

Expected

The documentation suggests that this would cause an Err-Result. (at least for Parser.int)

I personally expected python-like behaviour:

>>> int("0123")
123
>>> float("0123")
123.0

In any case, Ok 0 makes the user think, the input was correctly parsed, when in fact it was not.

Final Thoughts

I want to thank you for your work in the elm community and especially the nice design of the elm/parser. It's a blast to work with so far.

I'd be happy to contribute to a fix, if you too see this as a bug.

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