[macruby-changes] [5176] MacRuby/trunk/string.c

source_changes at macosforge.org source_changes at macosforge.org
Mon Jan 17 00:48:10 PST 2011


Revision: 5176
          http://trac.macosforge.org/projects/ruby/changeset/5176
Author:   watson1978 at gmail.com
Date:     2011-01-17 00:48:04 -0800 (Mon, 17 Jan 2011)
Log Message:
-----------
String#scan will return the Array which has untrusted element.

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

str = "hello hello hello".untrust
ary = str.scan("hello")
assert_equal(false, ary.untrusted?)
ary.each do |m|
  assert_equal(true, m.untrusted?)
end

str = "hello hello hello"
ary = str.scan("hello".untrust)
assert_equal(false, ary.untrusted?)
ary.each do |m|
  assert_equal(true, m.untrusted?)
end

str = "hello hello hello".untrust
ary = str.scan(/(.)/)
assert_equal(false, ary.untrusted?)
assert_equal(true, ary[0][0].untrusted?)

str = "hello hello hello"
ary = str.scan(/(.)/.untrust)
assert_equal(false, ary.untrusted?)
assert_equal(true, ary[0][0].untrusted?)

puts :ok
}}}

Modified Paths:
--------------
    MacRuby/trunk/string.c

Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c	2011-01-17 00:12:27 UTC (rev 5175)
+++ MacRuby/trunk/string.c	2011-01-17 08:48:04 UTC (rev 5176)
@@ -3034,6 +3034,7 @@
 {
     const bool block_given = rb_block_given_p();
 
+    const bool untrusted = OBJ_UNTRUSTED(self) || OBJ_UNTRUSTED(pat);
     pat = get_pat(pat, true);
     const bool tainted = OBJ_TAINTED(self) || OBJ_TAINTED(pat);
 
@@ -3069,6 +3070,9 @@
 	    if (tainted) {
 		OBJ_TAINT(scan_result);
 	    }
+	    if (untrusted) {
+		OBJ_UNTRUST(scan_result);
+	    }
 	}
 	else {
 	    scan_result = rb_ary_new2(count);
@@ -3078,6 +3082,9 @@
 		if (tainted) {
 		    OBJ_TAINT(substr);
 		}
+		if (untrusted) {
+		    OBJ_UNTRUST(substr);
+		}
 		rb_ary_push(scan_result, substr);
 	    }
 	}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20110117/4ed0cc58/attachment.html>


More information about the macruby-changes mailing list