From: Yusuke ENDOH Date: 2009-04-08T21:58:02+09:00 Subject: [ruby-dev:38294] [Bug:trunk] String#dump with non-ascii-compatible string provides invalid code 遠藤です。 アスキー非互換な文字列を String#dump すると eval できない文字列が 得られました。 $ ./ruby -e 'p "\u3042".encode("UTF-16LE").dump' "\"B0\".force_encoding(\"UTF-16LE\"\x00" Index: string.c =================================================================== --- string.c (revision 23159) +++ string.c (working copy) @@ -4291,7 +4291,7 @@ result = rb_str_new5(str, 0, len); p = RSTRING_PTR(str); pend = p + RSTRING_LEN(str); - q = RSTRING_PTR(result); qend = q + len; + q = RSTRING_PTR(result); qend = q + len + 1; *q++ = '"'; while (p < pend) { Index: test/ruby/test_m17n.rb =================================================================== --- test/ruby/test_m17n.rb (revision 23159) +++ test/ruby/test_m17n.rb (working copy) @@ -241,6 +241,9 @@ u("\xfc"), "\u3042", "ascii", + + "\u3042".encode("UTF-16LE"), + "\u3042".encode("UTF-16BE"), ].each do |str| assert_equal(str, eval(str.dump), "[ruby-dev:33142]") end -- Yusuke ENDOH