Skip to content

Commit e6188c4

Browse files
committed
[ruby/date] Date._parse does not accept nil
ruby/date@545066ca28
1 parent f13e68e commit e6188c4

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

ext/date/date_core.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4468,7 +4468,6 @@ static VALUE
44684468
check_limit(VALUE str, VALUE opt)
44694469
{
44704470
size_t slen, limit;
4471-
if (NIL_P(str)) return str;
44724471
StringValue(str);
44734472
slen = RSTRING_LEN(str);
44744473
limit = get_limit(opt);
@@ -4620,7 +4619,7 @@ date_s__iso8601(int argc, VALUE *argv, VALUE klass)
46204619
VALUE str, opt;
46214620

46224621
rb_scan_args(argc, argv, "1:", &str, &opt);
4623-
str = check_limit(str, opt);
4622+
if (!NIL_P(str)) str = check_limit(str, opt);
46244623

46254624
return date__iso8601(str);
46264625
}
@@ -4690,7 +4689,7 @@ date_s__rfc3339(int argc, VALUE *argv, VALUE klass)
46904689
VALUE str, opt;
46914690

46924691
rb_scan_args(argc, argv, "1:", &str, &opt);
4693-
str = check_limit(str, opt);
4692+
if (!NIL_P(str)) str = check_limit(str, opt);
46944693

46954694
return date__rfc3339(str);
46964695
}
@@ -4759,7 +4758,7 @@ date_s__xmlschema(int argc, VALUE *argv, VALUE klass)
47594758
VALUE str, opt;
47604759

47614760
rb_scan_args(argc, argv, "1:", &str, &opt);
4762-
str = check_limit(str, opt);
4761+
if (!NIL_P(str)) str = check_limit(str, opt);
47634762

47644763
return date__xmlschema(str);
47654764
}
@@ -4828,7 +4827,7 @@ date_s__rfc2822(int argc, VALUE *argv, VALUE klass)
48284827
VALUE str, opt;
48294828

48304829
rb_scan_args(argc, argv, "1:", &str, &opt);
4831-
str = check_limit(str, opt);
4830+
if (!NIL_P(str)) str = check_limit(str, opt);
48324831

48334832
return date__rfc2822(str);
48344833
}
@@ -4896,7 +4895,7 @@ date_s__httpdate(int argc, VALUE *argv, VALUE klass)
48964895
VALUE str, opt;
48974896

48984897
rb_scan_args(argc, argv, "1:", &str, &opt);
4899-
str = check_limit(str, opt);
4898+
if (!NIL_P(str)) str = check_limit(str, opt);
49004899

49014900
return date__httpdate(str);
49024901
}
@@ -4965,7 +4964,7 @@ date_s__jisx0301(int argc, VALUE *argv, VALUE klass)
49654964
VALUE str, opt;
49664965

49674966
rb_scan_args(argc, argv, "1:", &str, &opt);
4968-
str = check_limit(str, opt);
4967+
if (!NIL_P(str)) str = check_limit(str, opt);
49694968

49704969
return date__jisx0301(str);
49714970
}

test/date/test_date_parse.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,8 @@ def test__parse__2
544544

545545
h = Date._parse('')
546546
assert_equal({}, h)
547+
548+
assert_raise(TypeError) {Date._parse(nil)}
547549
end
548550

549551
def test_parse

0 commit comments

Comments
 (0)