Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ def xmlschema(time)
def rfc3339(time)
pattern = /\A\s*
(-?\d{4})-(\d\d)-(\d\d)
[T\s]
[T ]
(\d\d):(\d\d):(\d\d)
(\.\d+)?
(Z|[+-]\d\d:\d\d)
Expand Down
23 changes: 23 additions & 0 deletions test/test_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,29 @@ def test_huge_precision
define_method(test.sub(/xmlschema/, 'rfc3339')) {__send__(sub, :rfc3339)}
end

def test_rfc3339_separator
# RFC 3339 section 5.6 defines the separator as "T", and only notes that an
# application may use a space for readability. The other \s characters are
# not permitted, and Time.xmlschema has never accepted any of them.
t = Time.utc(2011, 10, 5, 22, 26, 12)
assert_equal(t, Time.rfc3339("2011-10-05T22:26:12Z"))
assert_equal(t, Time.rfc3339("2011-10-05 22:26:12Z"))

["\t", "\n", "\v", "\f", "\r"].each do |sep|
s = "2011-10-05#{sep}22:26:12Z"
e = assert_raise(ArgumentError, "separator #{sep.inspect}") { Time.rfc3339(s) }
assert_match(/invalid rfc3339 format/, e.message, "separator #{sep.inspect}")
end

# Time.xmlschema keeps rejecting every separator but "T".
assert_equal(t, Time.xmlschema("2011-10-05T22:26:12Z"))
["\t", "\n", "\v", "\f", "\r", " "].each do |sep|
assert_raise(ArgumentError, "separator #{sep.inspect}") do
Time.xmlschema("2011-10-05#{sep}22:26:12Z")
end
end
end

def test_parse_with_various_object
d = Date.new(2010, 10, 28)
dt = DateTime.new(2010, 10, 28)
Expand Down