1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/date] Fix misplaced time zone offset checks

https://github.com/ruby/date/commit/d21c69450a
This commit is contained in:
Nobuyoshi Nakada 2022-10-07 14:12:30 +09:00 committed by git
parent fc218e5977
commit 1b7c5c394f
2 changed files with 7 additions and 2 deletions

View file

@ -486,14 +486,14 @@ date_zone_to_diff(VALUE str)
#define out_of_range(v, min, max) ((v) < (min) || (max) < (v))
hour = STRTOUL(s, &p, 10);
if (*p == ':') {
if (out_of_range(sec, 0, 59)) return Qnil;
if (out_of_range(hour, 0, 23)) return Qnil;
s = ++p;
min = STRTOUL(s, &p, 10);
if (out_of_range(min, 0, 59)) return Qnil;
if (*p == ':') {
s = ++p;
sec = STRTOUL(s, &p, 10);
if (out_of_range(hour, 0, 23)) return Qnil;
if (out_of_range(sec, 0, 59)) return Qnil;
}
}
else if (*p == ',' || *p == '.') {

View file

@ -296,6 +296,11 @@ class TestDateStrptime < Test::Unit::TestCase
assert_not_nil(Date._strptime('Januari', '%B'))
assert_nil(Date._strptime('Sundai,', '%A,'))
assert_nil(Date._strptime('Januari,', '%B,'))
assert_nil(Date._strptime('+24:00', '%Z')[:offset])
assert_nil(Date._strptime('+23:60', '%Z')[:offset])
assert_nil(Date._strptime('+23:00:60', '%Z')[:offset])
assert_nil(Date._strptime('+23:00:60', '%Z')[:offset])
end
def test_strptime