haskell / aeson

A fast Haskell JSON library
Other
1.26k stars 321 forks source link

Reject space before timezone #1033

Closed phadej closed 1 year ago

phadej commented 1 year ago

Apprently aeson currently accepts space before timezone:

*Data.Aeson Data.Time> decode "\"2023-06-09T12:34:56 Z\"" :: Maybe UTCTime 
Just 2023-06-09 12:34:56 UTC

I suggest we remove this space, as I cannot find any hint we should accept it.

https://datatracker.ietf.org/doc/html/rfc3339#section-5.6 says

   date-fullyear   = 4DIGIT
   date-month      = 2DIGIT  ; 01-12
   date-mday       = 2DIGIT  ; 01-28, 01-29, 01-30, 01-31 based on
                             ; month/year
   time-hour       = 2DIGIT  ; 00-23
   time-minute     = 2DIGIT  ; 00-59
   time-second     = 2DIGIT  ; 00-58, 00-59, 00-60 based on leap second
                             ; rules
   time-secfrac    = "." 1*DIGIT
   time-numoffset  = ("+" / "-") time-hour ":" time-minute
   time-offset     = "Z" / time-numoffset

   partial-time    = time-hour ":" time-minute ":" time-second
                     [time-secfrac]
   full-date       = date-fullyear "-" date-month "-" date-mday
   full-time       = partial-time time-offset

   date-time       = full-date "T" full-time

(and in fact it says that NOTE: Per [ABNF] and ISO8601, the "T" and "Z" characters in this syntax may alternatively be lower case "t" or "z" respectively, which we don't accept - but that's another issue).

ping @Lysxia @bergmark

phadej commented 1 year ago

I made a fix in #1035 and none of our existing tests failed.

phadej commented 1 year ago

I'll merge #1035 now. Please comment if strongly disagree. There's still time until next release is cut.

phadej commented 1 year ago

ISO8601 2016 says (emphasis mine)

When it is required to indicate local time and the difference between the time scale of local time and UTC, the representation of the difference shall be appended to the representation of the local time following immediately, without space, the lowest order (extreme right-hand) time element of the local time expression.