From 4f78e7fff4949f5c94d35bce6b610d1188fd7c27 Mon Sep 17 00:00:00 2001 From: mame Date: Tue, 16 Mar 2010 16:26:04 +0000 Subject: [PATCH] * parse.y (rb_intern3): prohibit Symbol with an invalid encoding. [ruby-core:24621] * test/ruby/test_m17n_comb.rb: modify a test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ NEWS | 1 + parse.y | 4 ++++ test/ruby/test_m17n_comb.rb | 4 +++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 33c6d125e5..64b7f0a0c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Wed Mar 17 01:24:01 2010 Yusuke Endoh + + * parse.y (rb_intern3): prohibit Symbol with an invalid encoding. + [ruby-core:24621] + + * test/ruby/test_m17n_comb.rb: modify a test for above. + Tue Mar 16 22:51:11 2010 Tanaka Akira * tool/transcode-tblgen.rb: specialize for singletom mappings. diff --git a/NEWS b/NEWS index 56b4cf6833..0b6a946b74 100644 --- a/NEWS +++ b/NEWS @@ -313,6 +313,7 @@ with all sufficient information, see the ChangeLog file. * \d, \s, and \w are now ASCII only; use POSIX bracket classes and \p{} for Unicode semantics * $: no longer includes the current directory, use require_relative +* Symbol with an invalid encoding is forbidden to exist. === Compilation options diff --git a/parse.y b/parse.y index e338c6fa38..6a0e431083 100644 --- a/parse.y +++ b/parse.y @@ -9505,6 +9505,10 @@ rb_intern3(const char *name, long len, rb_encoding *enc) str = (VALUE)&fake_str; rb_enc_associate(str, enc); + if (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN) { + rb_raise(rb_eEncodingError, "invalid encoding symbol"); + } + if (st_lookup(global_symbols.sym_id, str, (st_data_t *)&id)) return id; diff --git a/test/ruby/test_m17n_comb.rb b/test/ruby/test_m17n_comb.rb index ab891363b1..cf80377172 100644 --- a/test/ruby/test_m17n_comb.rb +++ b/test/ruby/test_m17n_comb.rb @@ -1040,10 +1040,12 @@ class TestM17NComb < Test::Unit::TestCase STRINGS.each {|s| if /\0/ =~ a(s) assert_raise(ArgumentError) { s.intern } - else + elsif s.valid_encoding? sym = s.intern assert_equal(s, sym.to_s, "#{encdump s}.intern.to_s") assert_equal(sym, s.to_sym) + else + assert_raise(EncodingError) { s.intern } end } end