Issue #1843 has been updated by Yusuke Endoh.


Hi,

Brian Candler wrote:
> However Symbol#inspect raises an exception if it was made from a string with an invalid encoding.

Shyouhei Urabe wrote:
> My impression is that such symbols should be forbidden to exist.

Yui NARUSE wrote:
> I agree with shyouhei.


I guess we have already agreed the conclusion.  Must we wait for matz?



diff --git a/parse.y b/parse.y
index e338c6f..6a0e431 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 ab89136..cf80377 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

-- 
Yusuke ENDOH <mame / tsg.ne.jp>
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1843

----------------------------------------
http://redmine.ruby-lang.org