From 9340fbc9e23ef7e8afde978928dbd9e764f6bfd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Thu, 14 Dec 2017 18:56:51 +0100 Subject: [PATCH 1/2] Ensure time parser raises if timezone is missing --- spec/std/time/time_spec.cr | 9 +++++++++ src/time/format/parser.cr | 2 ++ 2 files changed, 11 insertions(+) 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/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 From 44bc85485ba8739a7750064f13f4b61f807e78d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Thu, 14 Dec 2017 19:34:39 +0100 Subject: [PATCH 2/2] Fix HTTP.parse_date formats --- src/http/common.cr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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