[macruby-changes] [4921] MacRuby/trunk/string.c
source_changes at macosforge.org
source_changes at macosforge.org
Sat Nov 20 20:36:58 PST 2010
Revision: 4921
http://trac.macosforge.org/projects/ruby/changeset/4921
Author: watson1978 at gmail.com
Date: 2010-11-20 20:36:55 -0800 (Sat, 20 Nov 2010)
Log Message:
-----------
String#gsub will copy the status of untrust.
Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
str = 'hello'
str.taint
str.untrust
str.freeze
s = str.gsub(/h/, "x")
assert_equal(true, s.tainted?)
assert_equal(true, s.untrusted?)
assert_equal(false, s.frozen?)
s = 'hello'
s.taint
s.untrust
s.gsub!(/h/, "x")
assert_equal(true, s.tainted?)
assert_equal(true, s.untrusted?)
assert_equal(false, s.frozen?)
s.freeze
assert_raise(RuntimeError) { s.gsub!(/0/, "x") }
str = 'hello'
rep = 'x'
rep.taint
rep.untrust
s = str.gsub(/h/, rep)
assert_equal(true, s.tainted?)
assert_equal(true, s.untrusted?)
assert_equal(false, s.frozen?)
s = str.gsub(/h/) { rep }
assert_equal(true, s.tainted?)
assert_equal(true, s.untrusted?)
assert_equal(false, s.frozen?)
puts :ok
}}}
Modified Paths:
--------------
MacRuby/trunk/string.c
Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c 2010-11-20 23:38:13 UTC (rev 4920)
+++ MacRuby/trunk/string.c 2010-11-21 04:36:55 UTC (rev 4921)
@@ -3875,6 +3875,7 @@
{
bool block_given = false;
bool tainted = false;
+ bool untrusted = false;
VALUE hash = Qnil, repl = Qnil;
switch (argc) {
@@ -3892,6 +3893,9 @@
if (OBJ_TAINTED(repl)) {
tainted = true;
}
+ if (OBJ_UNTRUSTED(repl)) {
+ untrusted = true;
+ }
break;
default:
@@ -3964,6 +3968,9 @@
if (OBJ_TAINTED(val)) {
tainted = true;
}
+ if (OBJ_UNTRUSTED(val)) {
+ untrusted = true;
+ }
changed = true;
offset = last = results[0].end;
@@ -3983,12 +3990,18 @@
if (!tainted && OBJ_TAINTED(str)) {
tainted = true;
}
+ if (!untrusted && OBJ_UNTRUSTED(str)) {
+ untrusted = true;
+ }
str = dest;
}
if (tainted) {
OBJ_TAINT(str);
}
+ if (untrusted) {
+ OBJ_UNTRUST(str);
+ }
return str;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101120/ef93c3f4/attachment.html>
More information about the macruby-changes
mailing list