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

ruby-changes:14869

From: mame <ko1@a...>
Date: Wed, 24 Feb 2010 00:43:45 +0900 (JST)
Subject: [ruby-changes:14869] Ruby:r26735 (trunk): * string.c (str_new_empty): String#split, partition, rpartition

mame	2010-02-24 00:41:34 +0900 (Wed, 24 Feb 2010)

  New Revision: 26735

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

  Log:
    * string.c (str_new_empty): String#split, partition, rpartition
      taints the resulting strings if self is tainted.

  Modified files:
    trunk/ChangeLog
    trunk/string.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26734)
+++ ChangeLog	(revision 26735)
@@ -1,3 +1,8 @@
+Wed Feb 24 00:39:17 2010  Yusuke Endoh  <mame@t...>
+
+	* string.c (str_new_empty): String#split, partition, rpartition
+	  taints the resulting strings if self is tainted.
+
 Mon Feb 22 21:35:33 2010  Tanaka Akira  <akr@f...>
 
 	* ext/digest/sha2/sha2init.c: test OpenSSL more strictly.
Index: string.c
===================================================================
--- string.c	(revision 26734)
+++ string.c	(revision 26735)
@@ -726,6 +726,14 @@
 	   rb_str_new_with_class, (obj, ptr, len))
 #define rb_str_new5 rb_str_new_with_class
 
+static VALUE
+str_new_empty(VALUE str)
+{
+    VALUE v = rb_str_new5(str, 0, 0);
+    OBJ_INFECT(v, str);
+    return v;
+}
+
 #define STR_BUF_MIN_SIZE 128
 
 VALUE
@@ -5578,7 +5586,7 @@
 	    regs = RMATCH_REGS(rb_backref_get());
 	    if (start == end && BEG(0) == END(0)) {
 		if (!ptr) {
-		    rb_ary_push(result, rb_str_new("", 0));
+		    rb_ary_push(result, str_new_empty(str));
 		    break;
 		}
 		else if (last_null == 1) {
@@ -5606,7 +5614,7 @@
 	    for (idx=1; idx < regs->num_regs; idx++) {
 		if (BEG(idx) == -1) continue;
 		if (BEG(idx) == END(idx))
-		    tmp = rb_str_new5(str, 0, 0);
+		    tmp = str_new_empty(str);
 		else
 		    tmp = rb_str_subseq(str, BEG(idx), END(idx)-BEG(idx));
 		rb_ary_push(result, tmp);
@@ -5616,7 +5624,7 @@
     }
     if (RSTRING_LEN(str) > 0 && (!NIL_P(limit) || RSTRING_LEN(str) > beg || lim < 0)) {
 	if (RSTRING_LEN(str) == beg)
-	    tmp = rb_str_new5(str, 0, 0);
+	    tmp = str_new_empty(str);
 	else
 	    tmp = rb_str_subseq(str, beg, RSTRING_LEN(str)-beg);
 	rb_ary_push(result, tmp);
@@ -6804,7 +6812,7 @@
     }
     if (pos < 0) {
       failed:
-	return rb_ary_new3(3, str, rb_str_new(0,0),rb_str_new(0,0));
+	return rb_ary_new3(3, str, str_new_empty(str), str_new_empty(str));
     }
     if (regex) {
 	sep = rb_str_subpat(str, sep, INT2FIX(0));
@@ -6854,7 +6862,7 @@
 	pos = rb_str_rindex(str, sep, pos);
     }
     if (pos < 0) {
-	return rb_ary_new3(3, rb_str_new(0,0),rb_str_new(0,0), str);
+	return rb_ary_new3(3, str_new_empty(str), str_new_empty(str), str);
     }
     if (regex) {
 	sep = rb_reg_nth_match(0, rb_backref_get());

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

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