Skip to content

Commit

Permalink
Date._<format>(nil) should return an empty Hash
Browse files Browse the repository at this point in the history
Fix: #39

This is how versions previous to 3.2.1 behaved and Active Support
currently rely on this behavior.

https://github.com/rails/rails/blob/90357af08048ef5076730505f6e7b14a81f33d0c/activesupport/lib/active_support/values/time_zone.rb#L383-L384

Any Rails application upgrading to date `3.2.1` might run into unexpected errors.
  • Loading branch information
byroot authored and mame committed Nov 18, 2021
1 parent 4f9b8e9 commit ae319af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ext/date/date_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -4306,6 +4306,8 @@ get_limit(VALUE opt)
static void
check_limit(VALUE str, VALUE opt)
{
if (NIL_P(str)) return;

StringValue(str);
size_t slen = RSTRING_LEN(str);
size_t limit = get_limit(opt);
Expand Down
18 changes: 18 additions & 0 deletions test/date/test_date_parse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,9 @@ def test__iso8601

h = Date._iso8601('')
assert_equal({}, h)

h = Date._iso8601(nil)
assert_equal({}, h)
end

def test__rfc3339
Expand All @@ -839,6 +842,9 @@ def test__rfc3339

h = Date._rfc3339('')
assert_equal({}, h)

h = Date._rfc3339(nil)
assert_equal({}, h)
end

def test__xmlschema
Expand Down Expand Up @@ -921,6 +927,9 @@ def test__xmlschema

h = Date._xmlschema('')
assert_equal({}, h)

h = Date._xmlschema(nil)
assert_equal({}, h)
end

def test__rfc2822
Expand Down Expand Up @@ -953,6 +962,9 @@ def test__rfc2822

h = Date._rfc2822('')
assert_equal({}, h)

h = Date._rfc2822(nil)
assert_equal({}, h)
end

def test__httpdate
Expand All @@ -973,6 +985,9 @@ def test__httpdate

h = Date._httpdate('')
assert_equal({}, h)

h = Date._httpdate(nil)
assert_equal({}, h)
end

def test__jisx0301
Expand Down Expand Up @@ -1001,6 +1016,9 @@ def test__jisx0301

h = Date._jisx0301('')
assert_equal({}, h)

h = Date._jisx0301(nil)
assert_equal({}, h)
end

def test_iso8601
Expand Down

0 comments on commit ae319af

Please sign in to comment.