[前][次][番号順一覧][スレッド一覧]

ruby-changes:12944

From: naruse <ko1@a...>
Date: Thu, 27 Aug 2009 15:10:49 +0900 (JST)
Subject: [ruby-changes:12944] Ruby:r24683 (trunk): * re.c (rb_reg_preprocess_dregexp): set encoding as ASCII-8BIT

naruse	2009-08-27 15:10:30 +0900 (Thu, 27 Aug 2009)

  New Revision: 24683

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24683

  Log:
    * re.c (rb_reg_preprocess_dregexp): set encoding as ASCII-8BIT
      when /n is specified and the embeded string is escaped text.

  Modified files:
    trunk/ChangeLog
    trunk/re.c
    trunk/test/ruby/test_regexp.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24682)
+++ ChangeLog	(revision 24683)
@@ -1,3 +1,8 @@
+Thu Aug 27 14:32:31 2009  NARUSE, Yui  <naruse@r...>
+
+	* 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@r...>
 
 	* random.c (random_rand): random integer can be a fixnum for
Index: re.c
===================================================================
--- re.c	(revision 24682)
+++ re.c	(revision 24683)
@@ -2285,9 +2285,11 @@
 
 	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);
Index: test/ruby/test_regexp.rb
===================================================================
--- test/ruby/test_regexp.rb	(revision 24682)
+++ test/ruby/test_regexp.rb	(revision 24683)
@@ -287,6 +287,7 @@
 
   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 }/ }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]