summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-27 06:10:30 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-27 06:10:30 +0000
commita20bd463a809aff8707acdeb90e8569b144e01d3 (patch)
tree381045cf9826a4c0f6f0e1ae3edd04c2871c6b95
parentf9be12fb14e57794d2edb53a141b00be47c7f010 (diff)
* re.c (rb_reg_preprocess_dregexp): set encoding as ASCII-8BIT
when /n is specified and the embeded string is escaped text. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--re.c8
-rw-r--r--test/ruby/test_regexp.rb1
3 files changed, 11 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 3fb1d3a69b..aa974df50e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Aug 27 14:32:31 2009 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * re.c (rb_reg_preprocess_dregexp): set encoding as ASCII-8BIT
+ when /n is specified and the embeded string is escaped text.
+
Thu Aug 27 13:51:12 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* random.c (random_rand): random integer can be a fixnum for
diff --git a/re.c b/re.c
index 053e673776..0cdadf537a 100644
--- a/re.c
+++ b/re.c
@@ -2285,9 +2285,11 @@ rb_reg_preprocess_dregexp(VALUE ary, int options)
src_enc = rb_enc_get(str);
if (options & ARG_ENCODING_NONE &&
- src_enc != ascii8bit &&
- rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
- rb_raise(rb_eRegexpError, "/.../n has a non escaped non ASCII character in non ASCII-8BIT script");
+ src_enc != ascii8bit) {
+ if (rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT)
+ rb_raise(rb_eRegexpError, "/.../n has a non escaped non ASCII character in non ASCII-8BIT script");
+ else
+ src_enc = ascii8bit;
}
StringValue(str);
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index 7631b6854d..a2911801bd 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -287,6 +287,7 @@ class TestRegexp < Test::Unit::TestCase
def test_unescape
assert_raise(ArgumentError) { s = '\\'; /#{ s }/ }
+ assert_equal(/\xFF/n, /#{ s="\\xFF" }/n)
assert_equal(/\177/, (s = '\177'; /#{ s }/))
assert_raise(ArgumentError) { s = '\u'; /#{ s }/ }
assert_raise(ArgumentError) { s = '\u{ ffffffff }'; /#{ s }/ }