haskell-hvr / cassava

A CSV parsing and encoding library optimized for ease of use and high performance
http://hackage.haskell.org/package/cassava
BSD 3-Clause "New" or "Revised" License
222 stars 105 forks source link

parseField does not range-check for Word16 #211

Open jchia opened 2 years ago

jchia commented 2 years ago

There is an instance of ParseField for Word16 and I was expecting it to fail for an input of "65536" because it is out-of-range.

I was surprised to find out that "65536" parses as 0:

ghci> runParser $ parseField @Word16 "65536"
Right 0

I think parseField on bounded integral types should do the necessary range-checking. The parseField for Word16 currently uses decimal from attoparsec, which does not do range checking. This issue affects different bounded integral types, not just Word16.

Related attoparsec issue: https://github.com/haskell/attoparsec/issues/211