summaryrefslogtreecommitdiff
path: root/lib/pathname.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-04-23 07:40:50 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-04-23 07:40:50 +0000
commitcd322e0403ed15cdf836b44f9dcb1b514c20fbd0 (patch)
tree020700992660a57334ce585c879e5f29ee5589ae /lib/pathname.rb
parenta6ed135520268c1dc0c0cc33188a241f93f736f3 (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/trunk@6205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/pathname.rb')
-rw-r--r--lib/pathname.rb34
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/pathname.rb b/lib/pathname.rb
index 05853689fd..118666b194 100644
--- a/lib/pathname.rb
+++ b/lib/pathname.rb
@@ -188,13 +188,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>)
@@ -1123,5 +1128,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