haskell-json icon indicating copy to clipboard operation
haskell-json copied to clipboard

Fix jsonNumber bug

Open sinogermany opened this issue 5 years ago • 0 comments

First of all, thanks @tsoding for your awesome youtube videos, really enjoyed it and learnt quite a few things from you.

And here goes the story:

I added a little helper function for my ghci convenience:

-- | Apply parser to an input, fails if anything's left in the input
parseInput :: Input -> Either ParserError JsonValue
parseInput i = do
  result <- runParser jsonValue i
  case result of
    (Input _ "", v) -> Right v
    (Input loc str, _) -> Left . ParserError loc $ "unexpected string remaining: " <> str

And when I ran your original code, I found something interesting:

*Main > parseInput . Input 0 $ "001"
Right (JsonNumber 1.0)

Obviously it's because of our most intelligent read function ¯\(ツ)/¯ .

After the PR changes it now becomes:

*Main > parseInput . Input 0 $ "001"
Left (ParserError 1 "unexpected string remaining: 01")

Sorry for the multiple commits to fix nits and make CI happy, feel free to squash merge.

Comments and suggestions welcome :)

sinogermany avatar May 24 '20 23:05 sinogermany