aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--lib/pathname.rb34
2 files changed, 38 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 6a7f31ac77..856033fdcc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Apr 23 16:38:46 2004 Tanaka Akira <akr@m17n.org>
+
+ * lib/pathname.rb: sync taint/freeze flag between
+ a pathname object and its internal string object.
+
Fri Apr 23 14:52:14 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (stmt, arg, aref_args): should not make sole splat into
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