Skip to content

Commit

Permalink
[Bug #20797] Check seconds in UTC offset as well as minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Oct 14, 2024
1 parent 0641951 commit 9611c61
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions spec/ruby/core/time/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -625,15 +625,15 @@ def obj.to_int; 3; end

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

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

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

it "raises ArgumentError if string has not ascii-compatible encoding" do
Expand Down
12 changes: 12 additions & 0 deletions test/ruby/test_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ def test_new_from_string
assert_raise_with_message(ArgumentError, /can't parse/) {
Time.new("2020-12-02 00:00:00 ")
}
assert_raise_with_message(ArgumentError, /utc_offset/) {
Time.new("2020-12-25 00:00:00 +0960")
}
assert_raise_with_message(ArgumentError, /utc_offset/) {
Time.new("2020-12-25 00:00:00 +09:60")
}
assert_raise_with_message(ArgumentError, /utc_offset/) {
Time.new("2020-12-25 00:00:00 +090060")
}
assert_raise_with_message(ArgumentError, /utc_offset/) {
Time.new("2020-12-25 00:00:00 +09:00:60")
}
end

def test_time_add()
Expand Down
1 change: 1 addition & 0 deletions time.c
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,7 @@ utc_offset_arg(VALUE arg)
}
if (sec) {
if (!have_2digits(sec)) goto invalid_utc_offset;
if (sec[0] > '5') goto invalid_utc_offset;
n += num_from_2digits(sec);
ASSUME(min);
}
Expand Down

0 comments on commit 9611c61

Please sign in to comment.