From 203ebcbb92db498f093a0b1936a28165b73f5ad3 Mon Sep 17 00:00:00 2001 From: naruse Date: Thu, 22 Jul 2010 07:29:32 +0000 Subject: * re.c (rb_reg_expr_str): fix broken Regexp#inspect when it is ASCII-8BIT and non-ASCII character. The length of character should be from original byte string. [ruby-core:31431] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ re.c | 3 ++- test/ruby/test_regexp.rb | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index f12f84a26d..3193874b18 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Jul 22 16:27:41 2010 NARUSE, Yui + + * re.c (rb_reg_expr_str): fix broken Regexp#inspect when it + is ASCII-8BIT and non-ASCII character. + The length of character should be from original byte string. + [ruby-core:31431] + Thu Jul 22 14:30:17 2010 NARUSE, Yui * include/ruby/missing.h: add prototype for ruby_close(). diff --git a/re.c b/re.c index db440d156a..f0213235c9 100644 --- a/re.c +++ b/re.c @@ -373,7 +373,8 @@ rb_reg_expr_str(VALUE str, const char *s, long len, int l; if (resenc) { unsigned int c = rb_enc_mbc_to_codepoint(p, pend, enc); - l = rb_str_buf_cat_escaped_char(str, c, unicode_p); + l = rb_enc_codelen(c, enc); + rb_str_buf_cat_escaped_char(str, c, unicode_p); } else { l = mbclen(p, pend, enc); diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 9e850b902e..35162310db 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -155,8 +155,8 @@ class TestRegexp < Test::Unit::TestCase assert_equal('/\/x/i', /\/x/i.inspect) assert_equal('/\x00/i', /#{"\0"}/i.inspect) assert_equal("/\n/i", /#{"\n"}/i.inspect) - s = [0xff].pack("C") - assert_equal('/\/\xFF/i', /\/#{s}/i.inspect) + s = [0xf1, 0xf2, 0xf3].pack("C*") + assert_equal('/\/\xF1\xF2\xF3/i', /\/#{s}/i.inspect) end def test_char_to_option -- cgit v1.2.3