diff --git a/spec/std/time/time_spec.cr b/spec/std/time/time_spec.cr index 7b55eb5776aa..e8bdfe1de3fb 100644 --- a/spec/std/time/time_spec.cr +++ b/spec/std/time/time_spec.cr @@ -624,6 +624,15 @@ describe Time do time.location.fixed?.should be_true end + it "raises when time zone missing" do + expect_raises(Time::Format::Error, "Invalid timezone") do + Time.parse("", "%z") + end + expect_raises(Time::Format::Error, "Invalid timezone") do + Time.parse("123456+01:00", "%3N%z") + end + end + # TODO %Z # TODO %G # TODO %g diff --git a/src/http/common.cr b/src/http/common.cr index b94e4a7a987b..604e06e76b72 100644 --- a/src/http/common.cr +++ b/src/http/common.cr @@ -4,7 +4,8 @@ {% end %} module HTTP - private DATE_PATTERNS = {"%a, %d %b %Y %H:%M:%S %z", "%d %b %Y %H:%M:%S %z", "%A, %d-%b-%y %H:%M:%S %z", "%a %b %e %H:%M:%S %Y"} + private DATE_PATTERNS = {"%a, %d %b %Y %H:%M:%S %z", "%d %b %Y %H:%M:%S %z", "%A, %d-%b-%y %H:%M:%S %z", "%a %b %e %H:%M:%S %Y", + "%a, %d %b %Y %H:%M:%S GMT", "%d %b %Y %H:%M:%S GMT", "%A, %d-%b-%y %H:%M:%S GMT", "%a %b %e %H:%M:%S %Y"} # :nodoc: MAX_HEADER_SIZE = 16_384 diff --git a/src/time/format/parser.cr b/src/time/format/parser.cr index 6b23fd1a60e4..faca5bf4f45b 100644 --- a/src/time/format/parser.cr +++ b/src/time/format/parser.cr @@ -284,6 +284,8 @@ struct Time::Format @reader.pos = pos end end + else + raise "Invalid timezone" end end