From 678494cec9b6d50000e26d1c7e7ad694e06dee1a Mon Sep 17 00:00:00 2001 From: Karchnu Date: Sat, 28 Nov 2020 02:56:01 +0100 Subject: [PATCH] Time.new fixed: now provides a Time instance or raises. --- src/cbor/from_cbor.cr | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cbor/from_cbor.cr b/src/cbor/from_cbor.cr index 864c6a7..80dab06 100644 --- a/src/cbor/from_cbor.cr +++ b/src/cbor/from_cbor.cr @@ -137,9 +137,9 @@ end # specified by [Section 2.4.1 of RFC 7049][1]. # # [1]: https://tools.ietf.org/html/rfc7049#section-2.4.1 -def Time.new(decoder : CBOR::Decoder) +def Time.new(decoder : CBOR::Decoder) : Time # In case Time is formatted as a JSON#to_json String. - case decoder.current_token + value = case decoder.current_token when CBOR::Token::StringT Time::Format::RFC_3339.parse(decoder.read_string) else @@ -157,6 +157,12 @@ def Time.new(decoder : CBOR::Decoder) raise CBOR::ParseError.new("Expected tag to have value 0 or 1, got #{tag.value}") end end + + unless value + raise CBOR::ParseError.new("could not parse time representation") + end + + value end # Reads the CBOR value as a BigInt.