mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* string.c (str_new_empty): String#split, partition, rpartition
taints the resulting strings if self is tainted. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26735 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7fbf889605
commit
24684a8a34
2 changed files with 18 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
|||
Wed Feb 24 00:39:17 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
||||
|
||||
* 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@fsij.org>
|
||||
|
||||
* ext/digest/sha2/sha2init.c: test OpenSSL more strictly.
|
||||
|
|
18
string.c
18
string.c
|
@ -726,6 +726,14 @@ RUBY_ALIAS_FUNCTION(rb_str_new5(VALUE obj, const char *ptr, long len),
|
|||
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 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
|||
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 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
|||
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 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
|||
}
|
||||
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 @@ rb_str_partition(VALUE str, VALUE sep)
|
|||
}
|
||||
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 @@ rb_str_rpartition(VALUE str, VALUE sep)
|
|||
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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue