aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-17 02:00:05 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-17 02:00:05 +0000
commit0f4199fb56ec12dae32a6fa099f15aaa7e55d10f (patch)
tree04c8df1b84a56c8b55f3f929b0d9744acfe7196c
parent35cb0f807b4689b0405dfbb2821e13f14c1fca45 (diff)
downloadruby-0f4199fb56ec12dae32a6fa099f15aaa7e55d10f.tar.gz
* 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
-rw-r--r--ChangeLog4
-rw-r--r--re.c7
-rw-r--r--test/ruby/test_m17n.rb18
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 <akr@fsij.org>
+
+ * re.c (rb_reg_quote): return US-ASCII string consistently.
+
Sun Feb 17 09:17:08 2008 Tanaka Akira <akr@fsij.org>
* 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)