From 1abeaee0aeb70abeb0f5f13d4d5ca83833309ff2 Mon Sep 17 00:00:00 2001 From: Amin Mansuri Date: Tue, 1 Sep 2026 06:02:34 -0300 Subject: [PATCH] Add Time.new specs for strings ending where a colon is expected Every other error-case string in core/time/new_spec.rb carries a trailing zone suffix, so no example ended at the byte where the parser expects a ':'. That is the one position where the message stops short of the offending byte, and it was unexercised. The gap turned up while investigating jruby/jruby#9623, where these three inputs read past the end of the string instead of raising ArgumentError. --- core/time/new_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/time/new_spec.rb b/core/time/new_spec.rb index 91ce4b2e3..0cde11c98 100644 --- a/core/time/new_spec.rb +++ b/core/time/new_spec.rb @@ -570,6 +570,23 @@ def obj.to_int; 3; end }.should.raise(ArgumentError, /missing min part: 00 |can't parse:/) end + # These strings end exactly at the byte where the parser expects a ':', so + # the message has no offending byte to append. The other error cases here + # all carry a trailing zone, which left that boundary unexercised. + it "raises ArgumentError if the time string ends where a ':' is expected" do + -> { + Time.new("2020-12-25 00:56") + }.should.raise(ArgumentError, /\Amissing sec part: 00:56\z|can't parse:/) + + -> { + Time.new("2020-12-25T00:56") + }.should.raise(ArgumentError, /\Amissing sec part: 00:56\z|can't parse:/) + + -> { + Time.new("2020-12-25 00") + }.should.raise(ArgumentError, /\Amissing min part: 00\z|can't parse:/) + end + it "raises ArgumentError if the time part is missing" do -> { Time.new("2020-12-25")