ruby-changes:71278
From: Nobuyoshi <ko1@a...>
Date: Fri, 25 Feb 2022 19:57:59 +0900 (JST)
Subject: [ruby-changes:71278] bb22bc76b0 (master): [ruby/date] Deprecate the unintentional ability to parse `Symbol`
https://git.ruby-lang.org/ruby.git/commit/?id=bb22bc76b0 From bb22bc76b08b8281d888424522790e0227ea09a4 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 25 Feb 2022 13:39:39 +0900 Subject: [ruby/date] Deprecate the unintentional ability to parse `Symbol` https://github.com/ruby/date/commit/d57818f3b3 --- ext/date/date_core.c | 10 +++++++++- ext/date/extconf.rb | 1 + test/date/test_date_parse.rb | 12 ++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ext/date/date_core.c b/ext/date/date_core.c index f6579b81e4..50d46e7a0c 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -4339,11 +4339,19 @@ get_limit(VALUE opt) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L4339 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); diff --git a/ext/date/extconf.rb b/ext/date/extconf.rb index f891de403d..358f64173a 100644 --- a/ext/date/extconf.rb +++ b/ext/date/extconf.rb @@ -3,6 +3,7 @@ require 'mkmf' https://github.com/ruby/ruby/blob/trunk/ext/date/extconf.rb#L3 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) diff --git a/test/date/test_date_parse.rb b/test/date/test_date_parse.rb index 574ead331e..746c947617 100644 --- a/test/date/test_date_parse.rb +++ b/test/date/test_date_parse.rb @@ -864,7 +864,7 @@ class TestDateParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_date_parse.rb#L864 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 @@ -886,7 +886,7 @@ class TestDateParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_date_parse.rb#L886 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 @@ -975,7 +975,7 @@ class TestDateParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_date_parse.rb#L975 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 @@ -1014,7 +1014,7 @@ class TestDateParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_date_parse.rb#L1014 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 @@ -1041,7 +1041,7 @@ class TestDateParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_date_parse.rb#L1041 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 @@ -1124,7 +1124,7 @@ class TestDateParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_date_parse.rb#L1124 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 -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/