* 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
@ -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>
|
Mon Feb 22 21:35:33 2010 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* ext/digest/sha2/sha2init.c: test OpenSSL more strictly.
|
* 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))
|
rb_str_new_with_class, (obj, ptr, len))
|
||||||
#define rb_str_new5 rb_str_new_with_class
|
#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
|
#define STR_BUF_MIN_SIZE 128
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
@ -5578,7 +5586,7 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
|||||||
regs = RMATCH_REGS(rb_backref_get());
|
regs = RMATCH_REGS(rb_backref_get());
|
||||||
if (start == end && BEG(0) == END(0)) {
|
if (start == end && BEG(0) == END(0)) {
|
||||||
if (!ptr) {
|
if (!ptr) {
|
||||||
rb_ary_push(result, rb_str_new("", 0));
|
rb_ary_push(result, str_new_empty(str));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (last_null == 1) {
|
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++) {
|
for (idx=1; idx < regs->num_regs; idx++) {
|
||||||
if (BEG(idx) == -1) continue;
|
if (BEG(idx) == -1) continue;
|
||||||
if (BEG(idx) == END(idx))
|
if (BEG(idx) == END(idx))
|
||||||
tmp = rb_str_new5(str, 0, 0);
|
tmp = str_new_empty(str);
|
||||||
else
|
else
|
||||||
tmp = rb_str_subseq(str, BEG(idx), END(idx)-BEG(idx));
|
tmp = rb_str_subseq(str, BEG(idx), END(idx)-BEG(idx));
|
||||||
rb_ary_push(result, tmp);
|
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) > 0 && (!NIL_P(limit) || RSTRING_LEN(str) > beg || lim < 0)) {
|
||||||
if (RSTRING_LEN(str) == beg)
|
if (RSTRING_LEN(str) == beg)
|
||||||
tmp = rb_str_new5(str, 0, 0);
|
tmp = str_new_empty(str);
|
||||||
else
|
else
|
||||||
tmp = rb_str_subseq(str, beg, RSTRING_LEN(str)-beg);
|
tmp = rb_str_subseq(str, beg, RSTRING_LEN(str)-beg);
|
||||||
rb_ary_push(result, tmp);
|
rb_ary_push(result, tmp);
|
||||||
@ -6804,7 +6812,7 @@ rb_str_partition(VALUE str, VALUE sep)
|
|||||||
}
|
}
|
||||||
if (pos < 0) {
|
if (pos < 0) {
|
||||||
failed:
|
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) {
|
if (regex) {
|
||||||
sep = rb_str_subpat(str, sep, INT2FIX(0));
|
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);
|
pos = rb_str_rindex(str, sep, pos);
|
||||||
}
|
}
|
||||||
if (pos < 0) {
|
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) {
|
if (regex) {
|
||||||
sep = rb_reg_nth_match(0, rb_backref_get());
|
sep = rb_reg_nth_match(0, rb_backref_get());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user