Skip to content

Commit daf4fce

Browse files
committed
Allow space separator in date-time regexes
[RFC 3339][0] is not very clear about what separator characters are allowed. It just lists "space" as an example: > NOTE: ISO 8601 defines date and time separated by "T". > Applications using this syntax may choose, for the sake of > readability, to specify a full-date and full-time separated by > (say) a space character. Ruby's [`DateTime.rfc3339`][1] allows `T`, `t`, and `\s`, so I'm going with that. This should only affect the edge case tests since everything else is delegated to `DateTime.rfc3339`. There are a bunch of tests that were generated here: https://ijmacd.github.io/rfc3339-iso8601/ Thanks to @pboling for pointing me to it in: #153 The RFC 3339 examples include some that use an underscore as the date-time separator, which I decided to ignore because it seems arbitrary to allow random characters and Ruby doesn't support it. [0]: https://datatracker.ietf.org/doc/html/rfc3339#section-5.6 [1]: https://github.com/ruby/ruby/blob/d3ea9070bbbf04749e5fcd8339d71a9e73a86cfb/ext/date/date_parse.c#L2613
1 parent 69fe7a8 commit daf4fce

File tree

2 files changed

+631
-2
lines changed

2 files changed

+631
-2
lines changed

lib/json_schemer/format.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ module Format
6868
end
6969

7070
DATE_TIME_OFFSET_REGEX = /(Z|[\+\-]([01][0-9]|2[0-3]):[0-5][0-9])\z/i.freeze
71-
HOUR_24_REGEX = /T24/.freeze
72-
LEAP_SECOND_REGEX = /T\d{2}:\d{2}:6/.freeze
71+
DATE_TIME_SEPARATOR_CHARACTER_CLASS = '[Tt\s]'
72+
HOUR_24_REGEX = /#{DATE_TIME_SEPARATOR_CHARACTER_CLASS}24:/.freeze
73+
LEAP_SECOND_REGEX = /#{DATE_TIME_SEPARATOR_CHARACTER_CLASS}\d{2}:\d{2}:6/.freeze
7374
IP_REGEX = /\A[\h:.]+\z/.freeze
7475
INVALID_QUERY_REGEX = /\s/.freeze
7576
IRI_ESCAPE_REGEX = /[^[:ascii:]]/

0 commit comments

Comments
 (0)