From 0f4199fb56ec12dae32a6fa099f15aaa7e55d10f Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 17 Feb 2008 02:00:05 +0000 Subject: * re.c (rb_reg_quote): return US-ASCII string consistently. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ re.c | 7 +++++-- test/ruby/test_m17n.rb | 18 ++++++++---------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2aaaaac33c..dc4e7a9bfa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sun Feb 17 10:59:04 2008 Tanaka Akira + + * re.c (rb_reg_quote): return US-ASCII string consistently. + Sun Feb 17 09:17:08 2008 Tanaka Akira * string.c (rb_str_times): reduce loop overhead. diff --git a/re.c b/re.c index f6bc8a205a..fe4365a2ee 100644 --- a/re.c +++ b/re.c @@ -2654,7 +2654,7 @@ rb_reg_quote(VALUE str) } s += clen; } - if (ascii_only && rb_enc_get_index(str) != 0) { + if (ascii_only) { str = rb_str_new3(str); rb_enc_associate(str, rb_usascii_encoding()); } @@ -2662,7 +2662,10 @@ rb_reg_quote(VALUE str) meta_found: tmp = rb_str_new(0, RSTRING_LEN(str)*2); - if (!ascii_only) { + if (ascii_only) { + rb_enc_associate(tmp, rb_usascii_encoding()); + } + else { rb_enc_copy(tmp, str); } t = RSTRING_PTR(tmp); diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index fe85941ba6..37accee3f8 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -523,16 +523,14 @@ class TestM17N < Test::Unit::TestCase def test_quote assert_regexp_generic_ascii(/#{Regexp.quote(a("a"))}#{Regexp.quote(e("e"))}/) - # Regexp.quote returns ASCII-8BIT string for ASCII only string - # to make generic regexp if possible. - assert_encoding("ASCII-8BIT", Regexp.quote(a("")).encoding) - assert_encoding("ASCII-8BIT", Regexp.quote(e("")).encoding) - assert_encoding("ASCII-8BIT", Regexp.quote(s("")).encoding) - assert_encoding("ASCII-8BIT", Regexp.quote(u("")).encoding) - assert_encoding("ASCII-8BIT", Regexp.quote(a("a")).encoding) - assert_encoding("ASCII-8BIT", Regexp.quote(e("a")).encoding) - assert_encoding("ASCII-8BIT", Regexp.quote(s("a")).encoding) - assert_encoding("ASCII-8BIT", Regexp.quote(u("a")).encoding) + assert_encoding("US-ASCII", Regexp.quote(a("")).encoding) + assert_encoding("US-ASCII", Regexp.quote(e("")).encoding) + assert_encoding("US-ASCII", Regexp.quote(s("")).encoding) + assert_encoding("US-ASCII", Regexp.quote(u("")).encoding) + assert_encoding("US-ASCII", Regexp.quote(a("a")).encoding) + assert_encoding("US-ASCII", Regexp.quote(e("a")).encoding) + assert_encoding("US-ASCII", Regexp.quote(s("a")).encoding) + assert_encoding("US-ASCII", Regexp.quote(u("a")).encoding) assert_encoding("ASCII-8BIT", Regexp.quote(a("\xc2\xa1")).encoding) assert_encoding("EUC-JP", Regexp.quote(e("\xc2\xa1")).encoding) -- cgit v1.2.3