diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-10-06 14:17:44 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-10-06 14:22:03 +0900 |
| commit | e6188c45e1114be3be4955971464f1b39d567d71 (patch) | |
| tree | d17e1312668593159a037faba29b16a3bbc97986 | |
| parent | f13e68e252ee96ee01e3b6eb11ad4109d5e033b1 (diff) | |
[ruby/date] `Date._parse` does not accept `nil`
https://github.com/ruby/date/commit/545066ca28
| -rw-r--r-- | ext/date/date_core.c | 13 | ||||
| -rw-r--r-- | test/date/test_date_parse.rb | 2 |
2 files changed, 8 insertions, 7 deletions
diff --git a/ext/date/date_core.c b/ext/date/date_core.c index 8a7859704b..e402105173 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -4468,7 +4468,6 @@ static VALUE check_limit(VALUE str, VALUE opt) { size_t slen, limit; - if (NIL_P(str)) return str; StringValue(str); slen = RSTRING_LEN(str); limit = get_limit(opt); @@ -4620,7 +4619,7 @@ date_s__iso8601(int argc, VALUE *argv, VALUE klass) VALUE str, opt; rb_scan_args(argc, argv, "1:", &str, &opt); - str = check_limit(str, opt); + if (!NIL_P(str)) str = check_limit(str, opt); return date__iso8601(str); } @@ -4690,7 +4689,7 @@ date_s__rfc3339(int argc, VALUE *argv, VALUE klass) VALUE str, opt; rb_scan_args(argc, argv, "1:", &str, &opt); - str = check_limit(str, opt); + if (!NIL_P(str)) str = check_limit(str, opt); return date__rfc3339(str); } @@ -4759,7 +4758,7 @@ date_s__xmlschema(int argc, VALUE *argv, VALUE klass) VALUE str, opt; rb_scan_args(argc, argv, "1:", &str, &opt); - str = check_limit(str, opt); + if (!NIL_P(str)) str = check_limit(str, opt); return date__xmlschema(str); } @@ -4828,7 +4827,7 @@ date_s__rfc2822(int argc, VALUE *argv, VALUE klass) VALUE str, opt; rb_scan_args(argc, argv, "1:", &str, &opt); - str = check_limit(str, opt); + if (!NIL_P(str)) str = check_limit(str, opt); return date__rfc2822(str); } @@ -4896,7 +4895,7 @@ date_s__httpdate(int argc, VALUE *argv, VALUE klass) VALUE str, opt; rb_scan_args(argc, argv, "1:", &str, &opt); - str = check_limit(str, opt); + if (!NIL_P(str)) str = check_limit(str, opt); return date__httpdate(str); } @@ -4965,7 +4964,7 @@ date_s__jisx0301(int argc, VALUE *argv, VALUE klass) VALUE str, opt; rb_scan_args(argc, argv, "1:", &str, &opt); - str = check_limit(str, opt); + if (!NIL_P(str)) str = check_limit(str, opt); return date__jisx0301(str); } diff --git a/test/date/test_date_parse.rb b/test/date/test_date_parse.rb index 29e55977c5..720624c02e 100644 --- a/test/date/test_date_parse.rb +++ b/test/date/test_date_parse.rb @@ -544,6 +544,8 @@ class TestDateParse < Test::Unit::TestCase h = Date._parse('') assert_equal({}, h) + + assert_raise(TypeError) {Date._parse(nil)} end def test_parse |
