Skip to content

Commit

Permalink
[ruby/date] Deprecate the unintentional ability to parse Symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu authored and matzbot committed Feb 25, 2022
1 parent d4f32b6 commit bb22bc7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
10 changes: 9 additions & 1 deletion ext/date/date_core.c
Expand Up @@ -4339,11 +4339,19 @@ get_limit(VALUE opt)
return 128;
}

#ifndef HAVE_RB_CATEGORY_WARN
#define rb_category_warn(category, fmt) rb_warn(fmt)
#endif

static void
check_limit(VALUE str, VALUE opt)
{
if (NIL_P(str)) return;
if (SYMBOL_P(str)) str = rb_sym2str(str);
if (SYMBOL_P(str)) {
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED,
"The ability to parse Symbol is an unintentional bug and is deprecated");
str = rb_sym2str(str);
}

StringValue(str);
size_t slen = RSTRING_LEN(str);
Expand Down
1 change: 1 addition & 0 deletions ext/date/extconf.rb
Expand Up @@ -3,6 +3,7 @@

config_string("strict_warnflags") {|w| $warnflags += " #{w}"}

have_func("rb_category_warn")
with_werror("", {:werror => true}) do |opt, |
have_var("timezone", "time.h", opt)
have_var("altzone", "time.h", opt)
Expand Down
12 changes: 6 additions & 6 deletions test/date/test_date_parse.rb
Expand Up @@ -864,7 +864,7 @@ def test__iso8601
h = Date._iso8601(nil)
assert_equal({}, h)

h = Date._iso8601('01-02-03T04:05:06Z'.to_sym)
h = assert_warn(/deprecated/) {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
Expand All @@ -886,7 +886,7 @@ def test__rfc3339
h = Date._rfc3339(nil)
assert_equal({}, h)

h = Date._rfc3339('2001-02-03T04:05:06Z'.to_sym)
h = assert_warn(/deprecated/) {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
Expand Down Expand Up @@ -975,7 +975,7 @@ def test__xmlschema
h = Date._xmlschema(nil)
assert_equal({}, h)

h = Date._xmlschema('2001-02-03'.to_sym)
h = assert_warn(/deprecated/) {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
Expand Down Expand Up @@ -1014,7 +1014,7 @@ def test__rfc2822
h = Date._rfc2822(nil)
assert_equal({}, h)

h = Date._rfc2822('Sat, 3 Feb 2001 04:05:06 UT'.to_sym)
h = assert_warn(/deprecated/) {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
Expand All @@ -1041,7 +1041,7 @@ def test__httpdate
h = Date._httpdate(nil)
assert_equal({}, h)

h = Date._httpdate('Sat, 03 Feb 2001 04:05:06 GMT'.to_sym)
h = assert_warn(/deprecated/) {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
Expand Down Expand Up @@ -1124,7 +1124,7 @@ def test__jisx0301
h = Date._jisx0301(nil)
assert_equal({}, h)

h = Date._jisx0301('H13.02.03T04:05:06.07+0100'.to_sym)
h = assert_warn(/deprecated/) {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
Expand Down

0 comments on commit bb22bc7

Please sign in to comment.