parser icon indicating copy to clipboard operation
parser copied to clipboard

Parser.int and Parser.float handle leading Zeros unexpectedly

Open maxmunzel opened this issue 5 years ago • 1 comments

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.

maxmunzel avatar Apr 23 '20 10:04 maxmunzel

Just noticed this too.

asett0 avatar May 23 '20 10:05 asett0