Skip to content

Commit bb22bc7

Browse files
nobumatzbot
authored andcommitted
[ruby/date] Deprecate the unintentional ability to parse Symbol
ruby/date@d57818f3b3
1 parent d4f32b6 commit bb22bc7

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

ext/date/date_core.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4339,11 +4339,19 @@ get_limit(VALUE opt)
43394339
return 128;
43404340
}
43414341

4342+
#ifndef HAVE_RB_CATEGORY_WARN
4343+
#define rb_category_warn(category, fmt) rb_warn(fmt)
4344+
#endif
4345+
43424346
static void
43434347
check_limit(VALUE str, VALUE opt)
43444348
{
43454349
if (NIL_P(str)) return;
4346-
if (SYMBOL_P(str)) str = rb_sym2str(str);
4350+
if (SYMBOL_P(str)) {
4351+
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED,
4352+
"The ability to parse Symbol is an unintentional bug and is deprecated");
4353+
str = rb_sym2str(str);
4354+
}
43474355

43484356
StringValue(str);
43494357
size_t slen = RSTRING_LEN(str);

ext/date/extconf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

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

6+
have_func("rb_category_warn")
67
with_werror("", {:werror => true}) do |opt, |
78
have_var("timezone", "time.h", opt)
89
have_var("altzone", "time.h", opt)

test/date/test_date_parse.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ def test__iso8601
864864
h = Date._iso8601(nil)
865865
assert_equal({}, h)
866866

867-
h = Date._iso8601('01-02-03T04:05:06Z'.to_sym)
867+
h = assert_warn(/deprecated/) {Date._iso8601('01-02-03T04:05:06Z'.to_sym)}
868868
assert_equal([2001, 2, 3, 4, 5, 6, 0],
869869
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
870870
end
@@ -886,7 +886,7 @@ def test__rfc3339
886886
h = Date._rfc3339(nil)
887887
assert_equal({}, h)
888888

889-
h = Date._rfc3339('2001-02-03T04:05:06Z'.to_sym)
889+
h = assert_warn(/deprecated/) {Date._rfc3339('2001-02-03T04:05:06Z'.to_sym)}
890890
assert_equal([2001, 2, 3, 4, 5, 6, 0],
891891
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
892892
end
@@ -975,7 +975,7 @@ def test__xmlschema
975975
h = Date._xmlschema(nil)
976976
assert_equal({}, h)
977977

978-
h = Date._xmlschema('2001-02-03'.to_sym)
978+
h = assert_warn(/deprecated/) {Date._xmlschema('2001-02-03'.to_sym)}
979979
assert_equal([2001, 2, 3, nil, nil, nil, nil],
980980
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
981981
end
@@ -1014,7 +1014,7 @@ def test__rfc2822
10141014
h = Date._rfc2822(nil)
10151015
assert_equal({}, h)
10161016

1017-
h = Date._rfc2822('Sat, 3 Feb 2001 04:05:06 UT'.to_sym)
1017+
h = assert_warn(/deprecated/) {Date._rfc2822('Sat, 3 Feb 2001 04:05:06 UT'.to_sym)}
10181018
assert_equal([2001, 2, 3, 4, 5, 6, 0],
10191019
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
10201020
end
@@ -1041,7 +1041,7 @@ def test__httpdate
10411041
h = Date._httpdate(nil)
10421042
assert_equal({}, h)
10431043

1044-
h = Date._httpdate('Sat, 03 Feb 2001 04:05:06 GMT'.to_sym)
1044+
h = assert_warn(/deprecated/) {Date._httpdate('Sat, 03 Feb 2001 04:05:06 GMT'.to_sym)}
10451045
assert_equal([2001, 2, 3, 4, 5, 6, 0],
10461046
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
10471047
end
@@ -1124,7 +1124,7 @@ def test__jisx0301
11241124
h = Date._jisx0301(nil)
11251125
assert_equal({}, h)
11261126

1127-
h = Date._jisx0301('H13.02.03T04:05:06.07+0100'.to_sym)
1127+
h = assert_warn(/deprecated/) {Date._jisx0301('H13.02.03T04:05:06.07+0100'.to_sym)}
11281128
assert_equal([2001, 2, 3, 4, 5, 6, 3600],
11291129
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
11301130
end

0 commit comments

Comments
 (0)