Skip to content

Commit 9611c61

Browse files
committed
[Bug #20797] Check seconds in UTC offset as well as minutes
1 parent 0641951 commit 9611c61

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

spec/ruby/core/time/new_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,15 +625,15 @@ def obj.to_int; 3; end
625625

626626
-> {
627627
Time.new("2020-12-25 00:56:17 +23:59:60")
628-
}.should raise_error(ArgumentError, "utc_offset out of range")
628+
}.should raise_error(ArgumentError, /utc_offset/)
629629

630630
-> {
631631
Time.new("2020-12-25 00:56:17 +24:00")
632-
}.should raise_error(ArgumentError, "utc_offset out of range")
632+
}.should raise_error(ArgumentError, /utc_offset/)
633633

634634
-> {
635635
Time.new("2020-12-25 00:56:17 +23:61")
636-
}.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +23:61')
636+
}.should raise_error(ArgumentError, /utc_offset/)
637637
end
638638

639639
it "raises ArgumentError if string has not ascii-compatible encoding" do

test/ruby/test_time.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ def test_new_from_string
152152
assert_raise_with_message(ArgumentError, /can't parse/) {
153153
Time.new("2020-12-02 00:00:00 ")
154154
}
155+
assert_raise_with_message(ArgumentError, /utc_offset/) {
156+
Time.new("2020-12-25 00:00:00 +0960")
157+
}
158+
assert_raise_with_message(ArgumentError, /utc_offset/) {
159+
Time.new("2020-12-25 00:00:00 +09:60")
160+
}
161+
assert_raise_with_message(ArgumentError, /utc_offset/) {
162+
Time.new("2020-12-25 00:00:00 +090060")
163+
}
164+
assert_raise_with_message(ArgumentError, /utc_offset/) {
165+
Time.new("2020-12-25 00:00:00 +09:00:60")
166+
}
155167
end
156168

157169
def test_time_add()

time.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,6 +2211,7 @@ utc_offset_arg(VALUE arg)
22112211
}
22122212
if (sec) {
22132213
if (!have_2digits(sec)) goto invalid_utc_offset;
2214+
if (sec[0] > '5') goto invalid_utc_offset;
22142215
n += num_from_2digits(sec);
22152216
ASSUME(min);
22162217
}

0 commit comments

Comments
 (0)