Skip to content

Commit

Permalink
check_limit: also handle symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Nov 16, 2021
1 parent 8f2d7a0 commit 376c659
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions ext/date/date_core.c
Expand Up @@ -4343,6 +4343,7 @@ static void
check_limit(VALUE str, VALUE opt)
{
if (NIL_P(str)) return;
if (SYMBOL_P(str)) str = rb_sym2str(str);

StringValue(str);
size_t slen = RSTRING_LEN(str);
Expand Down
24 changes: 24 additions & 0 deletions test/date/test_date_parse.rb
Expand Up @@ -851,6 +851,10 @@ def test__iso8601

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

h = Date._iso8601('01-02-03T04:05:06Z'.to_sym)
assert_equal([2001, 2, 3, 4, 5, 6, 0],
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end

def test__rfc3339
Expand All @@ -869,6 +873,10 @@ def test__rfc3339

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

h = Date._rfc3339('2001-02-03T04:05:06Z'.to_sym)
assert_equal([2001, 2, 3, 4, 5, 6, 0],
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end

def test__xmlschema
Expand Down Expand Up @@ -954,6 +962,10 @@ def test__xmlschema

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

h = Date._xmlschema('2001-02-03'.to_sym)
assert_equal([2001, 2, 3, nil, nil, nil, nil],
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end

def test__rfc2822
Expand Down Expand Up @@ -989,6 +1001,10 @@ def test__rfc2822

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

h = Date._rfc2822('Sat, 3 Feb 2001 04:05:06 UT'.to_sym)
assert_equal([2001, 2, 3, 4, 5, 6, 0],
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end

def test__httpdate
Expand All @@ -1012,6 +1028,10 @@ def test__httpdate

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

h = Date._httpdate('Sat, 03 Feb 2001 04:05:06 GMT'.to_sym)
assert_equal([2001, 2, 3, 4, 5, 6, 0],
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end

def test__jisx0301
Expand Down Expand Up @@ -1091,6 +1111,10 @@ def test__jisx0301

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

h = Date._jisx0301('H13.02.03T04:05:06.07+0100'.to_sym)
assert_equal([2001, 2, 3, 4, 5, 6, 3600],
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end

def test_iso8601
Expand Down

0 comments on commit 376c659

Please sign in to comment.