diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-04-23 07:40:50 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-04-23 07:40:50 +0000 |
commit | d449ece238050b720a4132cab4ad734d213c6eb8 (patch) | |
tree | 0665aea9f471e3e6615c45a0f96987de6f2194a2 /lib/pathname.rb | |
parent | 22a6ae4bf9a41931714cec80433911aff6be3f64 (diff) |
* lib/pathname.rb: sync taint/freeze flag between
a pathname object and its internal string object.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/pathname.rb')
-rw-r--r-- | lib/pathname.rb | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/pathname.rb b/lib/pathname.rb index 95f5be2752..15cc54baaa 100644 --- a/lib/pathname.rb +++ b/lib/pathname.rb @@ -186,13 +186,18 @@ class Pathname # def initialize(path) @path = path.to_str.dup - @path.freeze if /\0/ =~ @path raise ArgumentError, "pathname contains \\0: #{@path.inspect}" end + + self.taint if @path.tainted? end + def freeze() super; @path.freeze; self end + def taint() super; @path.taint; self end + def untaint() super; @path.untaint; self end + # # Compare this pathname with +other+. The comparison is string-based. # Be aware that two different paths (<tt>foo.txt</tt> and <tt>./foo.txt</tt>) @@ -1111,5 +1116,32 @@ if $0 == __FILE__ assert_pathname_plus('a/c', 'a/b', '../c') assert_pathname_plus('../../c', '..', '../c') end + + def test_taint + obj = Pathname.new("a"); assert_same(obj, obj.taint) + obj = Pathname.new("a"); assert_same(obj, obj.untaint) + + assert_equal(false, Pathname.new("a" ) .tainted?) + assert_equal(false, Pathname.new("a" ) .to_s.tainted?) + assert_equal(true, Pathname.new("a" ).taint .tainted?) + assert_equal(true, Pathname.new("a" ).taint.to_s.tainted?) + assert_equal(true, Pathname.new("a".taint) .tainted?) + assert_equal(true, Pathname.new("a".taint) .to_s.tainted?) + assert_equal(true, Pathname.new("a".taint).taint .tainted?) + assert_equal(true, Pathname.new("a".taint).taint.to_s.tainted?) + end + + def test_freeze + obj = Pathname.new("a"); assert_same(obj, obj.freeze) + + assert_equal(false, Pathname.new("a" ) .frozen?) + assert_equal(false, Pathname.new("a".freeze) .frozen?) + assert_equal(true, Pathname.new("a" ).freeze .frozen?) + assert_equal(true, Pathname.new("a".freeze).freeze .frozen?) + assert_equal(false, Pathname.new("a" ) .to_s.frozen?) + assert_equal(false, Pathname.new("a".freeze) .to_s.frozen?) + assert_equal(false, Pathname.new("a" ).freeze.to_s.frozen?) + assert_equal(false, Pathname.new("a".freeze).freeze.to_s.frozen?) + end end end |