Skip to content

Fix jsonNumber bug #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed

Fix jsonNumber bug #20

wants to merge 4 commits into from

Conversation

sinogermany
Copy link

@sinogermany sinogermany commented May 24, 2020

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 sinogermany closed this Feb 9, 2024
@sinogermany sinogermany deleted the fix-json-number-bug branch February 9, 2024 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant