Skip to content

Fix parsing of fractional NumericDate's - #10

Merged
puffnfresh merged 1 commit into
puffnfresh:masterfrom
ulidtko:fix-frac-dates-bug
Sep 24, 2026
Merged

puffnfresh merged 1 commit into
puffnfresh:masterfrom
ulidtko:fix-frac-dates-bug

Conversation

@ulidtko

@ulidtko ulidtko commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Basically, the bug was this:

λ ➔ eitherDecode "123.999999999" :: Either String NumericDate 
Right (NumericDate 123999999999)

caused by a misuse of Data.Scientific.coefficient, where the corresponding base10Exponent was being blissfully disregarded (incorrectly assumed always zero, I guess):

haskell-jwt/src/Web/JWT.hs

Lines 622 to 623 in 7543f3d

instance FromJSON NumericDate where
parseJSON (Number x) = return $ NumericDate $ coefficient x

I.e. aeson parses the number as expected — into 123999999999e-9:

λ ➔ (123.999999999 :: Scientific) == scientific 123999999999 (-9)
True

but the instance just drops the exponent on the floor. 🤷

Resolves #4.

Comment thread src/Web/JWT.hs
Comment thread src/Web/JWT.hs
@puffnfresh
puffnfresh merged commit 0e61d51 into puffnfresh:master Sep 24, 2026

@ulidtko ulidtko left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @puffnfresh, thanks! Would be also great to merge #9, please take a look 🙏

Comment thread src/Web/JWT.hs
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.

Misinterpretation of fractional NumericDates

2 participants