mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
a6ed135520
commit
cd322e0403
2 changed files with 38 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue