Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove taint methods #58

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions lib/inifile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,34 +323,21 @@ def freeze
self
end

# Public: Mark this IniFile as tainted -- this will traverse each section
# marking each as tainted.
#
# Returns this IniFile.
def taint
super
@ini.each_value {|h| h.taint}
@ini.taint
self
end

# Public: Produces a duplicate of this IniFile. The duplicate is independent
# of the original -- i.e. the duplicate can be modified without changing the
# original. The tainted state of the original is copied to the duplicate.
# original.
#
# Returns a new IniFile.
def dup
other = super
other.instance_variable_set(:@ini, Hash.new {|h,k| h[k] = Hash.new})
@ini.each_pair {|s,h| other[s].merge! h}
other.taint if self.tainted?
other
end

# Public: Produces a duplicate of this IniFile. The duplicate is independent
# of the original -- i.e. the duplicate can be modified without changing the
# original. The tainted state and the frozen state of the original is copied
# to the duplicate.
# original. The frozen state of the original is copied to the duplicate.
#
# Returns a new IniFile.
def clone
Expand Down
32 changes: 0 additions & 32 deletions test/test_inifile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,17 @@ def test_class_load
def test_clone
clone = @ini_file.clone
assert_equal @ini_file, clone
assert !clone.tainted?
assert !clone.frozen?

# the clone should be completely independent of the original
clone['new_section']['one'] = 1
assert_not_equal @ini_file, clone

# the tainted state is copied to clones
@ini_file.taint
assert @ini_file.tainted?

clone = @ini_file.clone
assert clone.tainted?

# the frozen state is also copied to clones
@ini_file.freeze
assert @ini_file.frozen?

clone = @ini_file.clone
assert clone.tainted?
assert clone.frozen?
end

Expand All @@ -94,26 +85,17 @@ def test_delete_section
def test_dup
dup = @ini_file.dup
assert_equal @ini_file, dup
assert !dup.tainted?
assert !dup.frozen?

# the duplicate should be completely independent of the original
dup['new_section']['one'] = 1
assert_not_equal @ini_file, dup

# the tainted state is copied to duplicates
@ini_file.taint
assert @ini_file.tainted?

dup = @ini_file.dup
assert dup.tainted?

# the frozen state, however, is not
@ini_file.freeze
assert @ini_file.frozen?

dup = @ini_file.dup
assert dup.tainted?
assert !dup.frozen?
end

Expand Down Expand Up @@ -311,20 +293,6 @@ def test_sections
assert_equal [], ini_file.sections
end

def test_taint
assert_equal false, @ini_file.tainted?
@ini_file.each_section do |s|
assert_equal false, @ini_file[s].tainted?
end

@ini_file.taint

assert_equal true, @ini_file.tainted?
@ini_file.each_section do |s|
assert_equal true, @ini_file[s].tainted?
end
end

def test_write
tmp = 'test/data/temp.ini'
File.delete tmp if Kernel.test(?f, tmp)
Expand Down