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

ruby-changes:2727

From: ko1@a...
Date: 14 Dec 2007 01:10:43 +0900
Subject: [ruby-changes:2727] matz - Ruby:r14218 (trunk): * re.c (rb_reg_initialize): embedded string may override encoding

matz	2007-12-14 01:09:53 +0900 (Fri, 14 Dec 2007)

  New Revision: 14218

  Modified files:
    trunk/ChangeLog
    trunk/re.c
    trunk/version.h

  Log:
    * re.c (rb_reg_initialize): embedded string may override encoding
      of the regular expression.
    
    * re.c (rb_reg_initialize): fix encoding of regular expression if
      embedded string has its own encoding specified.

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/version.h?r1=14218&r2=14217
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14218&r2=14217
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/re.c?r1=14218&r2=14217

Index: re.c
===================================================================
--- re.c	(revision 14217)
+++ re.c	(revision 14218)
@@ -1954,6 +1954,7 @@
     struct RRegexp *re = RREGEXP(obj);
     VALUE unescaped;
     rb_encoding *fixed_enc = 0;
+    rb_encoding *d_enc = rb_default_encoding();
 
     if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4)
 	rb_raise(rb_eSecurityError, "Insecure: can't modify regexp");
@@ -1969,15 +1970,19 @@
     if (unescaped == Qnil)
         return -1;
 
-    if (fixed_enc && fixed_enc != enc) {
-        strcpy(err, "character encodings differ");
-        return -1;
+    if (fixed_enc) {
+	if (fixed_enc != enc && enc != d_enc && fixed_enc != d_enc) {
+	    strcpy(err, "character encodings differ");
+	    return -1;
+	}
+        if (fixed_enc != d_enc) {
+	    options |= ARG_ENCODING_FIXED;
+	    enc = fixed_enc;
+	}
     }
-
-    if (fixed_enc)
-        enc = fixed_enc;
-    else if (!(options & ARG_ENCODING_FIXED))
-        enc = rb_default_encoding();
+    else if (!(options & ARG_ENCODING_FIXED)) {
+        enc = d_enc;
+    }
     
     rb_enc_associate((VALUE)re, enc);
     if ((options & ARG_ENCODING_FIXED) || fixed_enc) {
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14217)
+++ ChangeLog	(revision 14218)
@@ -1,3 +1,11 @@
+Fri Dec 14 00:54:40 2007  Yukihiro Matsumoto  <matz@r...>
+
+	* re.c (rb_reg_initialize): embedded string may override encoding
+	  of the regular expression.
+
+	* re.c (rb_reg_initialize): fix encoding of regular expression if
+	  embedded string has its own encoding specified.
+
 Thu Dec 13 22:16:46 2007  Yukihiro Matsumoto  <matz@r...>
 
 	* encoding.c (rb_enc_compatible): encoding should never fall back
Index: version.h
===================================================================
--- version.h	(revision 14217)
+++ version.h	(revision 14218)
@@ -1,7 +1,7 @@
 #define RUBY_VERSION "1.9.0"
-#define RUBY_RELEASE_DATE "2007-12-13"
+#define RUBY_RELEASE_DATE "2007-12-14"
 #define RUBY_VERSION_CODE 190
-#define RUBY_RELEASE_CODE 20071213
+#define RUBY_RELEASE_CODE 20071214
 #define RUBY_PATCHLEVEL 0
 
 #define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
 #define RUBY_VERSION_TEENY 0
 #define RUBY_RELEASE_YEAR 2007
 #define RUBY_RELEASE_MONTH 12
-#define RUBY_RELEASE_DAY 13
+#define RUBY_RELEASE_DAY 14
 
 #ifdef RUBY_EXTERN
 RUBY_EXTERN const char ruby_version[];

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

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