summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2024-10-14 13:55:55 +0900
committerNobuyoshi Nakada <[email protected]>2024-10-14 13:55:55 +0900
commit9611c619ac60e9aeb0341b0c8cf322a42707ce38 (patch)
treec50619d507c2da7cc7b7e1ad052ebc94e7e47ef8
parent0641951e7bd3fa7b8032a5a1206d15cfab8fae4f (diff)
[Bug #20797] Check seconds in UTC offset as well as minutes
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11892
-rw-r--r--spec/ruby/core/time/new_spec.rb6
-rw-r--r--test/ruby/test_time.rb12
-rw-r--r--time.c1
3 files changed, 16 insertions, 3 deletions
diff --git a/spec/ruby/core/time/new_spec.rb b/spec/ruby/core/time/new_spec.rb
index d686355270..9b3e4f90f3 100644
--- a/spec/ruby/core/time/new_spec.rb
+++ b/spec/ruby/core/time/new_spec.rb
@@ -625,15 +625,15 @@ describe "Time.new with a timezone argument" do
-> {
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
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index 99ee84f247..333edb8021 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -152,6 +152,18 @@ class TestTime < Test::Unit::TestCase
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()
diff --git a/time.c b/time.c
index 8abcc520ef..3c8ff36516 100644
--- a/time.c
+++ b/time.c
@@ -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);
}