ruby-changes:41576
From: nobu <ko1@a...>
Date: Mon, 25 Jan 2016 15:55:38 +0900 (JST)
Subject: [ruby-changes:41576] nobu:r53650 (trunk): symbol.c: more informative error message
nobu 2016-01-25 15:56:26 +0900 (Mon, 25 Jan 2016) New Revision: 53650 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53650 Log: symbol.c: more informative error message * symbol.c (sym_check_asciionly): more informative error message with the encoding name and the inspected content. [ruby-core:73398] [Feature #12016] Modified files: trunk/ChangeLog trunk/symbol.c trunk/test/ruby/test_symbol.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 53649) +++ ChangeLog (revision 53650) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Jan 25 15:55:30 2016 Nobuyoshi Nakada <nobu@r...> + + * symbol.c (sym_check_asciionly): more informative error message + with the encoding name and the inspected content. + [ruby-core:73398] [Feature #12016] + Mon Jan 25 09:38:26 2016 SHIBATA Hiroshi <hsbt@r...> * test/ruby/test_string.rb: added testcase for next!, succ and succ! Index: symbol.c =================================================================== --- symbol.c (revision 53649) +++ symbol.c (revision 53650) @@ -430,7 +430,8 @@ sym_check_asciionly(VALUE str) https://github.com/ruby/ruby/blob/trunk/symbol.c#L430 if (!rb_enc_asciicompat(rb_enc_get(str))) return FALSE; switch (rb_enc_str_coderange(str)) { case ENC_CODERANGE_BROKEN: - rb_raise(rb_eEncodingError, "invalid encoding symbol"); + rb_raise(rb_eEncodingError, "invalid symbol in encoding %s :%+"PRIsVALUE, + rb_enc_name(rb_enc_get(str)), str); case ENC_CODERANGE_7BIT: return TRUE; } Index: test/ruby/test_symbol.rb =================================================================== --- test/ruby/test_symbol.rb (revision 53649) +++ test/ruby/test_symbol.rb (revision 53650) @@ -262,7 +262,7 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_symbol.rb#L262 assert_equal(Encoding::US_ASCII, "$-A".force_encoding("iso-8859-15").intern.encoding) assert_equal(Encoding::US_ASCII, "foobar~!".force_encoding("iso-8859-15").intern.encoding) assert_equal(Encoding::UTF_8, "\u{2192}".intern.encoding) - assert_raise(EncodingError) {"\xb0a".force_encoding("utf-8").intern} + assert_raise_with_message(EncodingError, /\\xb0/i) {"\xb0a".force_encoding("utf-8").intern} end def test_singleton_method -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/