diff options
Diffstat (limited to 'spec/ruby/core')
90 files changed, 1844 insertions, 1464 deletions
diff --git a/spec/ruby/core/array/clear_spec.rb b/spec/ruby/core/array/clear_spec.rb index 8f83a012b7..d399d5a373 100644 --- a/spec/ruby/core/array/clear_spec.rb +++ b/spec/ruby/core/array/clear_spec.rb @@ -20,24 +20,28 @@ describe "Array#clear" do a.size.should == 0 end - it "keeps tainted status" do - a = [1] - a.taint - a.tainted?.should be_true - a.clear - a.tainted?.should be_true + ruby_version_is ''...'2.7' do + it "keeps tainted status" do + a = [1] + a.taint + a.tainted?.should be_true + a.clear + a.tainted?.should be_true + end end it "does not accept any arguments" do -> { [1].clear(true) }.should raise_error(ArgumentError) end - it "keeps untrusted status" do - a = [1] - a.untrust - a.untrusted?.should be_true - a.clear - a.untrusted?.should be_true + ruby_version_is ''...'2.7' do + it "keeps untrusted status" do + a = [1] + a.untrust + a.untrusted?.should be_true + a.clear + a.untrusted?.should be_true + end end it "raises a #{frozen_error_class} on a frozen array" do diff --git a/spec/ruby/core/array/compact_spec.rb b/spec/ruby/core/array/compact_spec.rb index ecccddeb9f..ee3dfc0ca2 100644 --- a/spec/ruby/core/array/compact_spec.rb +++ b/spec/ruby/core/array/compact_spec.rb @@ -22,16 +22,18 @@ describe "Array#compact" do ArraySpecs::MyArray[1, 2, 3, nil].compact.should be_an_instance_of(Array) end - it "does not keep tainted status even if all elements are removed" do - a = [nil, nil] - a.taint - a.compact.tainted?.should be_false - end + ruby_version_is ''...'2.7' do + it "does not keep tainted status even if all elements are removed" do + a = [nil, nil] + a.taint + a.compact.tainted?.should be_false + end - it "does not keep untrusted status even if all elements are removed" do - a = [nil, nil] - a.untrust - a.compact.untrusted?.should be_false + it "does not keep untrusted status even if all elements are removed" do + a = [nil, nil] + a.untrust + a.compact.untrusted?.should be_false + end end end @@ -57,18 +59,20 @@ describe "Array#compact!" do [1, 2, false, 3].compact!.should == nil end - it "keeps tainted status even if all elements are removed" do - a = [nil, nil] - a.taint - a.compact! - a.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "keeps tainted status even if all elements are removed" do + a = [nil, nil] + a.taint + a.compact! + a.tainted?.should be_true + end - it "keeps untrusted status even if all elements are removed" do - a = [nil, nil] - a.untrust - a.compact! - a.untrusted?.should be_true + it "keeps untrusted status even if all elements are removed" do + a = [nil, nil] + a.untrust + a.compact! + a.untrusted?.should be_true + end end it "raises a #{frozen_error_class} on a frozen array" do diff --git a/spec/ruby/core/array/concat_spec.rb b/spec/ruby/core/array/concat_spec.rb index cc707d9948..b297c091a3 100644 --- a/spec/ruby/core/array/concat_spec.rb +++ b/spec/ruby/core/array/concat_spec.rb @@ -41,60 +41,62 @@ describe "Array#concat" do -> { ArraySpecs.frozen_array.concat([]) }.should raise_error(frozen_error_class) end - it "keeps tainted status" do - ary = [1, 2] - ary.taint - ary.concat([3]) - ary.tainted?.should be_true - ary.concat([]) - ary.tainted?.should be_true - end - - it "is not infected by the other" do - ary = [1,2] - other = [3]; other.taint - ary.tainted?.should be_false - ary.concat(other) - ary.tainted?.should be_false - end - - it "keeps the tainted status of elements" do - ary = [ Object.new, Object.new, Object.new ] - ary.each {|x| x.taint } - - ary.concat([ Object.new ]) - ary[0].tainted?.should be_true - ary[1].tainted?.should be_true - ary[2].tainted?.should be_true - ary[3].tainted?.should be_false - end - - it "keeps untrusted status" do - ary = [1, 2] - ary.untrust - ary.concat([3]) - ary.untrusted?.should be_true - ary.concat([]) - ary.untrusted?.should be_true - end - - it "is not infected untrustedness by the other" do - ary = [1,2] - other = [3]; other.untrust - ary.untrusted?.should be_false - ary.concat(other) - ary.untrusted?.should be_false - end - - it "keeps the untrusted status of elements" do - ary = [ Object.new, Object.new, Object.new ] - ary.each {|x| x.untrust } - - ary.concat([ Object.new ]) - ary[0].untrusted?.should be_true - ary[1].untrusted?.should be_true - ary[2].untrusted?.should be_true - ary[3].untrusted?.should be_false + ruby_version_is ''...'2.7' do + it "keeps tainted status" do + ary = [1, 2] + ary.taint + ary.concat([3]) + ary.tainted?.should be_true + ary.concat([]) + ary.tainted?.should be_true + end + + it "is not infected by the other" do + ary = [1,2] + other = [3]; other.taint + ary.tainted?.should be_false + ary.concat(other) + ary.tainted?.should be_false + end + + it "keeps the tainted status of elements" do + ary = [ Object.new, Object.new, Object.new ] + ary.each {|x| x.taint } + + ary.concat([ Object.new ]) + ary[0].tainted?.should be_true + ary[1].tainted?.should be_true + ary[2].tainted?.should be_true + ary[3].tainted?.should be_false + end + + it "keeps untrusted status" do + ary = [1, 2] + ary.untrust + ary.concat([3]) + ary.untrusted?.should be_true + ary.concat([]) + ary.untrusted?.should be_true + end + + it "is not infected untrustedness by the other" do + ary = [1,2] + other = [3]; other.untrust + ary.untrusted?.should be_false + ary.concat(other) + ary.untrusted?.should be_false + end + + it "keeps the untrusted status of elements" do + ary = [ Object.new, Object.new, Object.new ] + ary.each {|x| x.untrust } + + ary.concat([ Object.new ]) + ary[0].untrusted?.should be_true + ary[1].untrusted?.should be_true + ary[2].untrusted?.should be_true + ary[3].untrusted?.should be_false + end end it "appends elements to an Array with enough capacity that has been shifted" do diff --git a/spec/ruby/core/array/delete_at_spec.rb b/spec/ruby/core/array/delete_at_spec.rb index c3111fe3d8..0ed56c18bb 100644 --- a/spec/ruby/core/array/delete_at_spec.rb +++ b/spec/ruby/core/array/delete_at_spec.rb @@ -39,23 +39,25 @@ describe "Array#delete_at" do -> { [1,2,3].freeze.delete_at(0) }.should raise_error(frozen_error_class) end - it "keeps tainted status" do - ary = [1, 2] - ary.taint - ary.tainted?.should be_true - ary.delete_at(0) - ary.tainted?.should be_true - ary.delete_at(0) # now empty - ary.tainted?.should be_true - end - - it "keeps untrusted status" do - ary = [1, 2] - ary.untrust - ary.untrusted?.should be_true - ary.delete_at(0) - ary.untrusted?.should be_true - ary.delete_at(0) # now empty - ary.untrusted?.should be_true + ruby_version_is ''...'2.7' do + it "keeps tainted status" do + ary = [1, 2] + ary.taint + ary.tainted?.should be_true + ary.delete_at(0) + ary.tainted?.should be_true + ary.delete_at(0) # now empty + ary.tainted?.should be_true + end + + it "keeps untrusted status" do + ary = [1, 2] + ary.untrust + ary.untrusted?.should be_true + ary.delete_at(0) + ary.untrusted?.should be_true + ary.delete_at(0) # now empty + ary.untrusted?.should be_true + end end end diff --git a/spec/ruby/core/array/delete_if_spec.rb b/spec/ruby/core/array/delete_if_spec.rb index 9f22f7e086..2312917c41 100644 --- a/spec/ruby/core/array/delete_if_spec.rb +++ b/spec/ruby/core/array/delete_if_spec.rb @@ -47,18 +47,20 @@ describe "Array#delete_if" do -> { ArraySpecs.empty_frozen_array.delete_if {} }.should raise_error(frozen_error_class) end - it "keeps tainted status" do - @a.taint - @a.tainted?.should be_true - @a.delete_if{ true } - @a.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "keeps tainted status" do + @a.taint + @a.tainted?.should be_true + @a.delete_if{ true } + @a.tainted?.should be_true + end - it "keeps untrusted status" do - @a.untrust - @a.untrusted?.should be_true - @a.delete_if{ true } - @a.untrusted?.should be_true + it "keeps untrusted status" do + @a.untrust + @a.untrusted?.should be_true + @a.delete_if{ true } + @a.untrusted?.should be_true + end end it_behaves_like :enumeratorized_with_origin_size, :delete_if, [1,2,3] diff --git a/spec/ruby/core/array/delete_spec.rb b/spec/ruby/core/array/delete_spec.rb index c55f4ad672..41e211e660 100644 --- a/spec/ruby/core/array/delete_spec.rb +++ b/spec/ruby/core/array/delete_spec.rb @@ -44,23 +44,25 @@ describe "Array#delete" do -> { [1, 2, 3].freeze.delete(1) }.should raise_error(frozen_error_class) end - it "keeps tainted status" do - a = [1, 2] - a.taint - a.tainted?.should be_true - a.delete(2) - a.tainted?.should be_true - a.delete(1) # now empty - a.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "keeps tainted status" do + a = [1, 2] + a.taint + a.tainted?.should be_true + a.delete(2) + a.tainted?.should be_true + a.delete(1) # now empty + a.tainted?.should be_true + end - it "keeps untrusted status" do - a = [1, 2] - a.untrust - a.untrusted?.should be_true - a.delete(2) - a.untrusted?.should be_true - a.delete(1) # now empty - a.untrusted?.should be_true + it "keeps untrusted status" do + a = [1, 2] + a.untrust + a.untrusted?.should be_true + a.delete(2) + a.untrusted?.should be_true + a.delete(1) # now empty + a.untrusted?.should be_true + end end end diff --git a/spec/ruby/core/array/flatten_spec.rb b/spec/ruby/core/array/flatten_spec.rb index b506f899b4..66af20ad70 100644 --- a/spec/ruby/core/array/flatten_spec.rb +++ b/spec/ruby/core/array/flatten_spec.rb @@ -145,12 +145,14 @@ describe "Array#flatten" do end end - it "returns a tainted array if self is tainted" do - [].taint.flatten.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "returns a tainted array if self is tainted" do + [].taint.flatten.tainted?.should be_true + end - it "returns an untrusted array if self is untrusted" do - [].untrust.flatten.untrusted?.should be_true + it "returns an untrusted array if self is untrusted" do + [].untrust.flatten.untrusted?.should be_true + end end it "performs respond_to? and method_missing-aware checks when coercing elements to array" do diff --git a/spec/ruby/core/array/multiply_spec.rb b/spec/ruby/core/array/multiply_spec.rb index ab654ce489..4060666d4b 100644 --- a/spec/ruby/core/array/multiply_spec.rb +++ b/spec/ruby/core/array/multiply_spec.rb @@ -88,42 +88,44 @@ describe "Array#* with an integer" do end end - it "copies the taint status of the original array even if the passed count is 0" do - ary = [1, 2, 3] - ary.taint - (ary * 0).tainted?.should == true - end + ruby_version_is ''...'2.7' do + it "copies the taint status of the original array even if the passed count is 0" do + ary = [1, 2, 3] + ary.taint + (ary * 0).tainted?.should == true + end - it "copies the taint status of the original array even if the array is empty" do - ary = [] - ary.taint - (ary * 3).tainted?.should == true - end + it "copies the taint status of the original array even if the array is empty" do + ary = [] + ary.taint + (ary * 3).tainted?.should == true + end - it "copies the taint status of the original array if the passed count is not 0" do - ary = [1, 2, 3] - ary.taint - (ary * 1).tainted?.should == true - (ary * 2).tainted?.should == true - end + it "copies the taint status of the original array if the passed count is not 0" do + ary = [1, 2, 3] + ary.taint + (ary * 1).tainted?.should == true + (ary * 2).tainted?.should == true + end - it "copies the untrusted status of the original array even if the passed count is 0" do - ary = [1, 2, 3] - ary.untrust - (ary * 0).untrusted?.should == true - end + it "copies the untrusted status of the original array even if the passed count is 0" do + ary = [1, 2, 3] + ary.untrust + (ary * 0).untrusted?.should == true + end - it "copies the untrusted status of the original array even if the array is empty" do - ary = [] - ary.untrust - (ary * 3).untrusted?.should == true - end + it "copies the untrusted status of the original array even if the array is empty" do + ary = [] + ary.untrust + (ary * 3).untrusted?.should == true + end - it "copies the untrusted status of the original array if the passed count is not 0" do - ary = [1, 2, 3] - ary.untrust - (ary * 1).untrusted?.should == true - (ary * 2).untrusted?.should == true + it "copies the untrusted status of the original array if the passed count is not 0" do + ary = [1, 2, 3] + ary.untrust + (ary * 1).untrusted?.should == true + (ary * 2).untrusted?.should == true + end end end diff --git a/spec/ruby/core/array/pack/p_spec.rb b/spec/ruby/core/array/pack/p_spec.rb index 857d403313..d7dff8a4da 100644 --- a/spec/ruby/core/array/pack/p_spec.rb +++ b/spec/ruby/core/array/pack/p_spec.rb @@ -15,14 +15,16 @@ describe "Array#pack with format 'P'" do ["hello"].pack("P").unpack("P5").should == ["hello"] end - it "taints the input string" do - input_string = "hello" - [input_string].pack("P") - input_string.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "taints the input string" do + input_string = "hello" + [input_string].pack("P") + input_string.tainted?.should be_true + end - it "does not taint the output string in normal cases" do - ["hello"].pack("P").tainted?.should be_false + it "does not taint the output string in normal cases" do + ["hello"].pack("P").tainted?.should be_false + end end it "with nil gives a null pointer" do @@ -42,14 +44,16 @@ describe "Array#pack with format 'p'" do ["hello"].pack("p").unpack("p").should == ["hello"] end - it "taints the input string" do - input_string = "hello" - [input_string].pack("p") - input_string.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "taints the input string" do + input_string = "hello" + [input_string].pack("p") + input_string.tainted?.should be_true + end - it "does not taint the output string in normal cases" do - ["hello"].pack("p").tainted?.should be_false + it "does not taint the output string in normal cases" do + ["hello"].pack("p").tainted?.should be_false + end end it "with nil gives a null pointer" do diff --git a/spec/ruby/core/array/pack/shared/basic.rb b/spec/ruby/core/array/pack/shared/basic.rb index bc366987c8..9061273ad6 100644 --- a/spec/ruby/core/array/pack/shared/basic.rb +++ b/spec/ruby/core/array/pack/shared/basic.rb @@ -33,8 +33,10 @@ describe :array_pack_basic_non_float, shared: true do [@obj, @obj].pack(d).should be_an_instance_of(String) end - it "taints the output string if the format string is tainted" do - [@obj, @obj].pack("x"+pack_format.taint).tainted?.should be_true + ruby_version_is ''...'2.7' do + it "taints the output string if the format string is tainted" do + [@obj, @obj].pack("x"+pack_format.taint).tainted?.should be_true + end end end @@ -49,8 +51,10 @@ describe :array_pack_basic_float, shared: true do [1.2, 4.7].pack(d).should be_an_instance_of(String) end - it "taints the output string if the format string is tainted" do - [3.2, 2.8].pack("x"+pack_format.taint).tainted?.should be_true + ruby_version_is ''...'2.7' do + it "taints the output string if the format string is tainted" do + [3.2, 2.8].pack("x"+pack_format.taint).tainted?.should be_true + end end end diff --git a/spec/ruby/core/array/pack/shared/taint.rb b/spec/ruby/core/array/pack/shared/taint.rb index 88f349cb24..565f04b8b9 100644 --- a/spec/ruby/core/array/pack/shared/taint.rb +++ b/spec/ruby/core/array/pack/shared/taint.rb @@ -1,33 +1,35 @@ describe :array_pack_taint, shared: true do - it "returns a tainted string when a pack argument is tainted" do - ["abcd".taint, 0x20].pack(pack_format("3C")).tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "returns a tainted string when a pack argument is tainted" do + ["abcd".taint, 0x20].pack(pack_format("3C")).tainted?.should be_true + end - it "does not return a tainted string when the array is tainted" do - ["abcd", 0x20].taint.pack(pack_format("3C")).tainted?.should be_false - end + it "does not return a tainted string when the array is tainted" do + ["abcd", 0x20].taint.pack(pack_format("3C")).tainted?.should be_false + end - it "returns a tainted string when the format is tainted" do - ["abcd", 0x20].pack(pack_format("3C").taint).tainted?.should be_true - end + it "returns a tainted string when the format is tainted" do + ["abcd", 0x20].pack(pack_format("3C").taint).tainted?.should be_true + end - it "returns a tainted string when an empty format is tainted" do - ["abcd", 0x20].pack("".taint).tainted?.should be_true - end + it "returns a tainted string when an empty format is tainted" do + ["abcd", 0x20].pack("".taint).tainted?.should be_true + end - it "returns a untrusted string when the format is untrusted" do - ["abcd", 0x20].pack(pack_format("3C").untrust).untrusted?.should be_true - end + it "returns a untrusted string when the format is untrusted" do + ["abcd", 0x20].pack(pack_format("3C").untrust).untrusted?.should be_true + end - it "returns a untrusted string when the empty format is untrusted" do - ["abcd", 0x20].pack("".untrust).untrusted?.should be_true - end + it "returns a untrusted string when the empty format is untrusted" do + ["abcd", 0x20].pack("".untrust).untrusted?.should be_true + end - it "returns a untrusted string when a pack argument is untrusted" do - ["abcd".untrust, 0x20].pack(pack_format("3C")).untrusted?.should be_true - end + it "returns a untrusted string when a pack argument is untrusted" do + ["abcd".untrust, 0x20].pack(pack_format("3C")).untrusted?.should be_true + end - it "returns a trusted string when the array is untrusted" do - ["abcd", 0x20].untrust.pack(pack_format("3C")).untrusted?.should be_false + it "returns a trusted string when the array is untrusted" do + ["abcd", 0x20].untrust.pack(pack_format("3C")).untrusted?.should be_false + end end end diff --git a/spec/ruby/core/array/plus_spec.rb b/spec/ruby/core/array/plus_spec.rb index 7692163980..45f8438208 100644 --- a/spec/ruby/core/array/plus_spec.rb +++ b/spec/ruby/core/array/plus_spec.rb @@ -41,17 +41,19 @@ describe "Array#+" do ([5, 6] + ArraySpecs::ToAryArray[1, 2]).should == [5, 6, 1, 2] end - it "does not get infected even if an original array is tainted" do - ([1, 2] + [3, 4]).tainted?.should be_false - ([1, 2].taint + [3, 4]).tainted?.should be_false - ([1, 2] + [3, 4].taint).tainted?.should be_false - ([1, 2].taint + [3, 4].taint).tainted?.should be_false - end - - it "does not infected even if an original array is untrusted" do - ([1, 2] + [3, 4]).untrusted?.should be_false - ([1, 2].untrust + [3, 4]).untrusted?.should be_false - ([1, 2] + [3, 4].untrust).untrusted?.should be_false - ([1, 2].untrust + [3, 4].untrust).untrusted?.should be_false + ruby_version_is ''...'2.7' do + it "does not get infected even if an original array is tainted" do + ([1, 2] + [3, 4]).tainted?.should be_false + ([1, 2].taint + [3, 4]).tainted?.should be_false + ([1, 2] + [3, 4].taint).tainted?.should be_false + ([1, 2].taint + [3, 4].taint).tainted?.should be_false + end + + it "does not infected even if an original array is untrusted" do + ([1, 2] + [3, 4]).untrusted?.should be_false + ([1, 2].untrust + [3, 4]).untrusted?.should be_false + ([1, 2] + [3, 4].untrust).untrusted?.should be_false + ([1, 2].untrust + [3, 4].untrust).untrusted?.should be_false + end end end diff --git a/spec/ruby/core/array/pop_spec.rb b/spec/ruby/core/array/pop_spec.rb index 7dbd6cb3cc..2cfecbb2b4 100644 --- a/spec/ruby/core/array/pop_spec.rb +++ b/spec/ruby/core/array/pop_spec.rb @@ -30,12 +30,14 @@ describe "Array#pop" do array.pop.should == [1, 'two', 3.0, array, array, array, array] end - it "keeps taint status" do - a = [1, 2].taint - a.pop - a.tainted?.should be_true - a.pop - a.tainted?.should be_true + ruby_version_is ''...'2.7' do + it "keeps taint status" do + a = [1, 2].taint + a.pop + a.tainted?.should be_true + a.pop + a.tainted?.should be_true + end end it "raises a #{frozen_error_class} on a frozen array" do @@ -46,12 +48,14 @@ describe "Array#pop" do -> { ArraySpecs.empty_frozen_array.pop }.should raise_error(frozen_error_class) end - it "keeps untrusted status" do - a = [1, 2].untrust - a.pop - a.untrusted?.should be_true - a.pop - a.untrusted?.should be_true + ruby_version_is ''...'2.7' do + it "keeps untrusted status" do + a = [1, 2].untrust + a.pop + a.untrusted?.should be_true + a.pop + a.untrusted?.should be_true + end end describe "passed a number n as an argument" do @@ -132,24 +136,26 @@ describe "Array#pop" do ArraySpecs::MyArray[1, 2, 3].pop(2).should be_an_instance_of(Array) end - it "returns an untainted array even if the array is tainted" do - ary = [1, 2].taint - ary.pop(2).tainted?.should be_false - ary.pop(0).tainted?.should be_false - end - - it "keeps taint status" do - a = [1, 2].taint - a.pop(2) - a.tainted?.should be_true - a.pop(2) - a.tainted?.should be_true - end - - it "returns a trusted array even if the array is untrusted" do - ary = [1, 2].untrust - ary.pop(2).untrusted?.should be_false - ary.pop(0).untrusted?.should be_false + ruby_version_is ''...'2.7' do + it "returns an untainted array even if the array is tainted" do + ary = [1, 2].taint + ary.pop(2).tainted?.should be_false + ary.pop(0).tainted?.should be_false + end + + it "keeps taint status" do + a = [1, 2].taint + a.pop(2) + a.tainted?.should be_true + a.pop(2) + a.tainted?.should be_true + end + + it "returns a trusted array even if the array is untrusted" do + ary = [1, 2].untrust + ary.pop(2).untrusted?.should be_false + ary.pop(0).untrusted?.should be_false + end end it "raises a #{frozen_error_class} on a frozen array" do @@ -157,12 +163,14 @@ describe "Array#pop" do -> { ArraySpecs.frozen_array.pop(0) }.should raise_error(frozen_error_class) end - it "keeps untrusted status" do - a = [1, 2].untrust - a.pop(2) - a.untrusted?.should be_true - a.pop(2) - a.untrusted?.should be_true + ruby_version_is ''...'2.7' do + it "keeps untrusted status" do + a = [1, 2].untrust + a.pop(2) + a.untrusted?.should be_true + a.pop(2) + a.untrusted?.should be_true + end end end end diff --git a/spec/ruby/core/array/shared/clone.rb b/spec/ruby/core/array/shared/clone.rb index 95d0d0a3d5..f6f581b17c 100644 --- a/spec/ruby/core/array/shared/clone.rb +++ b/spec/ruby/core/array/shared/clone.rb @@ -18,25 +18,27 @@ describe :array_clone, shared: true do b.__id__.should_not == a.__id__ end - it "copies taint status from the original" do - a = [1, 2, 3, 4] - b = [1, 2, 3, 4] - a.taint - aa = a.send @method - bb = b.send @method + ruby_version_is ''...'2.7' do + it "copies taint status from the original" do + a = [1, 2, 3, 4] + b = [1, 2, 3, 4] + a.taint + aa = a.send @method + bb = b.send @method - aa.tainted?.should == true - bb.tainted?.should == false - end + aa.tainted?.should == true + bb.tainted?.should == false + end - it "copies untrusted status from the original" do - a = [1, 2, 3, 4] - b = [1, 2, 3, 4] - a.untrust - aa = a.send @method - bb = b.send @method + it "copies untrusted status from the original" do + a = [1, 2, 3, 4] + b = [1, 2, 3, 4] + a.untrust + aa = a.send @method + bb = b.send @method - aa.untrusted?.should == true - bb.untrusted?.should == false + aa.untrusted?.should == true + bb.untrusted?.should == false + end end end diff --git a/spec/ruby/core/array/shared/collect.rb b/spec/ruby/core/array/shared/collect.rb index 80e2739893..cbe32d2ab4 100644 --- a/spec/ruby/core/array/shared/collect.rb +++ b/spec/ruby/core/array/shared/collect.rb @@ -42,16 +42,18 @@ describe :array_collect, shared: true do }.should raise_error(ArgumentError) end - it "does not copy tainted status" do - a = [1, 2, 3] - a.taint - a.send(@method){|x| x}.tainted?.should be_false - end + ruby_version_is ''...'2.7' do + it "does not copy tainted status" do + a = [1, 2, 3] + a.taint + a.send(@method){|x| x}.tainted?.should be_false + end - it "does not copy untrusted status" do - a = [1, 2, 3] - a.untrust - a.send(@method){|x| x}.untrusted?.should be_false + it "does not copy untrusted status" do + a = [1, 2, 3] + a.untrust + a.send(@method){|x| x}.untrusted?.should be_false + end end before :all do @@ -94,19 +96,21 @@ describe :array_collect_b, shared: true do a.should == ["1!", "2!", "3!"] end - it "keeps tainted status" do - a = [1, 2, 3] - a.taint - a.tainted?.should be_true - a.send(@method){|x| x} - a.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "keeps tainted status" do + a = [1, 2, 3] + a.taint + a.tainted?.should be_true + a.send(@method){|x| x} + a.tainted?.should be_true + end - it "keeps untrusted status" do - a = [1, 2, 3] - a.untrust - a.send(@method){|x| x} - a.untrusted?.should be_true + it "keeps untrusted status" do + a = [1, 2, 3] + a.untrust + a.send(@method){|x| x} + a.untrusted?.should be_true + end end describe "when frozen" do diff --git a/spec/ruby/core/array/shared/inspect.rb b/spec/ruby/core/array/shared/inspect.rb index 434440c25b..736f8d946b 100644 --- a/spec/ruby/core/array/shared/inspect.rb +++ b/spec/ruby/core/array/shared/inspect.rb @@ -64,28 +64,30 @@ describe :array_inspect, shared: true do ArraySpecs.empty_recursive_array.send(@method).should == "[[...]]" end - it "taints the result if the Array is non-empty and tainted" do - [1, 2].taint.send(@method).tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "taints the result if the Array is non-empty and tainted" do + [1, 2].taint.send(@method).tainted?.should be_true + end - it "does not taint the result if the Array is tainted but empty" do - [].taint.send(@method).tainted?.should be_false - end + it "does not taint the result if the Array is tainted but empty" do + [].taint.send(@method).tainted?.should be_false + end - it "taints the result if an element is tainted" do - ["str".taint].send(@method).tainted?.should be_true - end + it "taints the result if an element is tainted" do + ["str".taint].send(@method).tainted?.should be_true + end - it "untrusts the result if the Array is untrusted" do - [1, 2].untrust.send(@method).untrusted?.should be_true - end + it "untrusts the result if the Array is untrusted" do + [1, 2].untrust.send(@method).untrusted?.should be_true + end - it "does not untrust the result if the Array is untrusted but empty" do - [].untrust.send(@method).untrusted?.should be_false - end + it "does not untrust the result if the Array is untrusted but empty" do + [].untrust.send(@method).untrusted?.should be_false + end - it "untrusts the result if an element is untrusted" do - ["str".untrust].send(@method).untrusted?.should be_true + it "untrusts the result if an element is untrusted" do + ["str".untrust].send(@method).untrusted?.should be_true + end end describe "with encoding" do diff --git a/spec/ruby/core/array/shared/join.rb b/spec/ruby/core/array/shared/join.rb index 38bdde9502..5e7193de8a 100644 --- a/spec/ruby/core/array/shared/join.rb +++ b/spec/ruby/core/array/shared/join.rb @@ -58,32 +58,34 @@ describe :array_join_with_default_separator, shared: true do -> { ArraySpecs.empty_recursive_array.send(@method) }.should raise_error(ArgumentError) end - it "taints the result if the Array is tainted and non-empty" do - [1, 2].taint.send(@method).tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "taints the result if the Array is tainted and non-empty" do + [1, 2].taint.send(@method).tainted?.should be_true + end - it "does not taint the result if the Array is tainted but empty" do - [].taint.send(@method).tainted?.should be_false - end + it "does not taint the result if the Array is tainted but empty" do + [].taint.send(@method).tainted?.should be_false + end - it "taints the result if the result of coercing an element is tainted" do - s = mock("taint") - s.should_receive(:to_s).and_return("str".taint) - [s].send(@method).tainted?.should be_true - end + it "taints the result if the result of coercing an element is tainted" do + s = mock("taint") + s.should_receive(:to_s).and_return("str".taint) + [s].send(@method).tainted?.should be_true + end - it "untrusts the result if the Array is untrusted and non-empty" do - [1, 2].untrust.send(@method).untrusted?.should be_true - end + it "untrusts the result if the Array is untrusted and non-empty" do + [1, 2].untrust.send(@method).untrusted?.should be_true + end - it "does not untrust the result if the Array is untrusted but empty" do - [].untrust.send(@method).untrusted?.should be_false - end + it "does not untrust the result if the Array is untrusted but empty" do + [].untrust.send(@method).untrusted?.should be_false + end - it "untrusts the result if the result of coercing an element is untrusted" do - s = mock("untrust") - s.should_receive(:to_s).and_return("str".untrust) - [s].send(@method).untrusted?.should be_true + it "untrusts the result if the result of coercing an element is untrusted" do + s = mock("untrust") + s.should_receive(:to_s).and_return("str".untrust) + [s].send(@method).untrusted?.should be_true + end end it "uses the first encoding when other strings are compatible" do @@ -125,39 +127,41 @@ describe :array_join_with_string_separator, shared: true do [1, [2, ArraySpecs::MyArray[3, 4], 5], 6].send(@method, ":").should == "1:2:3:4:5:6" end - describe "with a tainted separator" do - before :each do - @sep = ":".taint - end + ruby_version_is ''...'2.7' do + describe "with a tainted separator" do + before :each do + @sep = ":".taint + end - it "does not taint the result if the array is empty" do - [].send(@method, @sep).tainted?.should be_false - end + it "does not taint the result if the array is empty" do + [].send(@method, @sep).tainted?.should be_false + end - it "does not taint the result if the array has only one element" do - [1].send(@method, @sep).tainted?.should be_false - end + it "does not taint the result if the array has only one element" do + [1].send(@method, @sep).tainted?.should be_false + end - it "taints the result if the array has two or more elements" do - [1, 2].send(@method, @sep).tainted?.should be_true + it "taints the result if the array has two or more elements" do + [1, 2].send(@method, @sep).tainted?.should be_true + end end - end - describe "with an untrusted separator" do - before :each do - @sep = ":".untrust - end + describe "with an untrusted separator" do + before :each do + @sep = ":".untrust + end - it "does not untrust the result if the array is empty" do - [].send(@method, @sep).untrusted?.should be_false - end + it "does not untrust the result if the array is empty" do + [].send(@method, @sep).untrusted?.should be_false + end - it "does not untrust the result if the array has only one element" do - [1].send(@method, @sep).untrusted?.should be_false - end + it "does not untrust the result if the array has only one element" do + [1].send(@method, @sep).untrusted?.should be_false + end - it "untrusts the result if the array has two or more elements" do - [1, 2].send(@method, @sep).untrusted?.should be_true + it "untrusts the result if the array has two or more elements" do + [1, 2].send(@method, @sep).untrusted?.should be_true + end end end end diff --git a/spec/ruby/core/array/shift_spec.rb b/spec/ruby/core/array/shift_spec.rb index ef3c9fe1cd..13f1abbbfe 100644 --- a/spec/ruby/core/array/shift_spec.rb +++ b/spec/ruby/core/array/shift_spec.rb @@ -117,18 +117,20 @@ describe "Array#shift" do ArraySpecs::MyArray[1, 2, 3].shift(2).should be_an_instance_of(Array) end - it "returns an untainted array even if the array is tainted" do - ary = [1, 2].taint - ary.shift(2).tainted?.should be_false - ary.shift(0).tainted?.should be_false - end - - it "keeps taint status" do - a = [1, 2].taint - a.shift(2) - a.tainted?.should be_true - a.shift(2) - a.tainted?.should be_true + ruby_version_is ''...'2.7' do + it "returns an untainted array even if the array is tainted" do + ary = [1, 2].taint + ary.shift(2).tainted?.should be_false + ary.shift(0).tainted?.should be_false + end + + it "keeps taint status" do + a = [1, 2].taint + a.shift(2) + a.tainted?.should be_true + a.shift(2) + a.tainted?.should be_true + end end end end diff --git a/spec/ruby/core/array/uniq_spec.rb b/spec/ruby/core/array/uniq_spec.rb index c9bdd3dacd..4b56f3c841 100644 --- a/spec/ruby/core/array/uniq_spec.rb +++ b/spec/ruby/core/array/uniq_spec.rb @@ -39,44 +39,76 @@ describe "Array#uniq" do [x, y].uniq.should == [x, y] end - it "compares elements with matching hash codes with #eql?" do - a = Array.new(2) do - obj = mock('0') - obj.should_receive(:hash).at_least(1).and_return(0) - - def obj.eql?(o) - # It's undefined whether the impl does a[0].eql?(a[1]) or - # a[1].eql?(a[0]) so we taint both. - taint - o.taint - false + ruby_version_is '2.7' do + it "compares elements with matching hash codes with #eql?" do + a = Array.new(2) do + obj = mock('0') + obj.should_receive(:hash).at_least(1).and_return(0) + + def obj.eql?(o) + false + end + + obj end - obj - end + a.uniq.should == a - a.uniq.should == a - a[0].tainted?.should == true - a[1].tainted?.should == true + a = Array.new(2) do + obj = mock('0') + obj.should_receive(:hash).at_least(1).and_return(0) - a = Array.new(2) do - obj = mock('0') - obj.should_receive(:hash).at_least(1).and_return(0) + def obj.eql?(o) + true + end - def obj.eql?(o) - # It's undefined whether the impl does a[0].eql?(a[1]) or - # a[1].eql?(a[0]) so we taint both. - taint - o.taint - true + obj end - obj + a.uniq.size.should == 1 end + end - a.uniq.size.should == 1 - a[0].tainted?.should == true - a[1].tainted?.should == true + ruby_version_is ''...'2.7' do + it "compares elements with matching hash codes with #eql?" do + a = Array.new(2) do + obj = mock('0') + obj.should_receive(:hash).at_least(1).and_return(0) + + def obj.eql?(o) + # It's undefined whether the impl does a[0].eql?(a[1]) or + # a[1].eql?(a[0]) so we taint both. + taint + o.taint + false + end + + obj + end + + a.uniq.should == a + a[0].tainted?.should == true + a[1].tainted?.should == true + + a = Array.new(2) do + obj = mock('0') + obj.should_receive(:hash).at_least(1).and_return(0) + + def obj.eql?(o) + # It's undefined whether the impl does a[0].eql?(a[1]) or + # a[1].eql?(a[0]) so we taint both. + taint + o.taint + true + end + + obj + end + + a.uniq.size.should == 1 + a[0].tainted?.should == true + a[1].tainted?.should == true + end end it "compares elements based on the value returned from the block" do diff --git a/spec/ruby/core/enumerable/group_by_spec.rb b/spec/ruby/core/enumerable/group_by_spec.rb index 580a90cf0c..52b5a68d64 100644 --- a/spec/ruby/core/enumerable/group_by_spec.rb +++ b/spec/ruby/core/enumerable/group_by_spec.rb @@ -33,12 +33,14 @@ describe "Enumerable#group_by" do [3, 4, 5] => [[3, 4, 5]] } end - it "returns a tainted hash if self is tainted" do - EnumerableSpecs::Empty.new.taint.group_by {}.tainted?.should be_true - end - - it "returns an untrusted hash if self is untrusted" do - EnumerableSpecs::Empty.new.untrust.group_by {}.untrusted?.should be_true + ruby_version_is ''...'2.7' do + it "returns a tainted hash if self is tainted" do + EnumerableSpecs::Empty.new.taint.group_by {}.tainted?.should be_true + end + + it "returns an untrusted hash if self is untrusted" do + EnumerableSpecs::Empty.new.untrust.group_by {}.untrusted?.should be_true + end end it_behaves_like :enumerable_enumeratorized_with_origin_size, :group_by diff --git a/spec/ruby/core/enumerable/shared/entries.rb b/spec/ruby/core/enumerable/shared/entries.rb index f52844cb45..590ce73bcf 100644 --- a/spec/ruby/core/enumerable/shared/entries.rb +++ b/spec/ruby/core/enumerable/shared/entries.rb @@ -14,11 +14,13 @@ describe :enumerable_entries, shared: true do count.arguments_passed.should == [:hello, "world"] end - it "returns a tainted array if self is tainted" do - EnumerableSpecs::Empty.new.taint.send(@method).tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "returns a tainted array if self is tainted" do + EnumerableSpecs::Empty.new.taint.send(@method).tainted?.should be_true + end - it "returns an untrusted array if self is untrusted" do - EnumerableSpecs::Empty.new.untrust.send(@method).untrusted?.should be_true + it "returns an untrusted array if self is untrusted" do + EnumerableSpecs::Empty.new.untrust.send(@method).untrusted?.should be_true + end end end diff --git a/spec/ruby/core/enumerable/uniq_spec.rb b/spec/ruby/core/enumerable/uniq_spec.rb index c286882e92..82c041d4ef 100644 --- a/spec/ruby/core/enumerable/uniq_spec.rb +++ b/spec/ruby/core/enumerable/uniq_spec.rb @@ -31,44 +31,76 @@ describe 'Enumerable#uniq' do [x, y].to_enum.uniq.should == [x, y] end - it "compares elements with matching hash codes with #eql?" do - a = Array.new(2) do - obj = mock('0') - obj.should_receive(:hash).at_least(1).and_return(0) - - def obj.eql?(o) - # It's undefined whether the impl does a[0].eql?(a[1]) or - # a[1].eql?(a[0]) so we taint both. - taint - o.taint - false + ruby_version_is '2.7' do + it "compares elements with matching hash codes with #eql?" do + a = Array.new(2) do + obj = mock('0') + obj.should_receive(:hash).at_least(1).and_return(0) + + def obj.eql?(o) + false + end + + obj end - obj - end + a.uniq.should == a - a.uniq.should == a - a[0].tainted?.should == true - a[1].tainted?.should == true + a = Array.new(2) do + obj = mock('0') + obj.should_receive(:hash).at_least(1).and_return(0) - a = Array.new(2) do - obj = mock('0') - obj.should_receive(:hash).at_least(1).and_return(0) + def obj.eql?(o) + true + end - def obj.eql?(o) - # It's undefined whether the impl does a[0].eql?(a[1]) or - # a[1].eql?(a[0]) so we taint both. - taint - o.taint - true + obj end - obj + a.to_enum.uniq.size.should == 1 end + end + + ruby_version_is ''...'2.7' do + it "compares elements with matching hash codes with #eql?" do + a = Array.new(2) do + obj = mock('0') + obj.should_receive(:hash).at_least(1).and_return(0) + + def obj.eql?(o) + # It's undefined whether the impl does a[0].eql?(a[1]) or + # a[1].eql?(a[0]) so we taint both. + taint + o.taint + false + end + + obj + end + + a.uniq.should == a + a[0].tainted?.should == true + a[1].tainted?.should == true + + a = Array.new(2) do + obj = mock('0') + obj.should_receive(:hash).at_least(1).and_return(0) + + def obj.eql?(o) + # It's undefined whether the impl does a[0].eql?(a[1]) or + # a[1].eql?(a[0]) so we taint both. + taint + o.taint + true + end + + obj + end - a.to_enum.uniq.size.should == 1 - a[0].tainted?.should == true - a[1].tainted?.should == true + a.to_enum.uniq.size.should == 1 + a[0].tainted?.should == true + a[1].tainted?.should == true + end end context 'when yielded with multiple arguments' do diff --git a/spec/ruby/core/hash/reject_spec.rb b/spec/ruby/core/hash/reject_spec.rb index 8016be5e83..1051ebd76c 100644 --- a/spec/ruby/core/hash/reject_spec.rb +++ b/spec/ruby/core/hash/reject_spec.rb @@ -32,9 +32,11 @@ describe "Hash#reject" do HashSpecs::MyHash[1 => 2, 3 => 4].reject { true }.should be_kind_of(Hash) end - it "does not taint the resulting hash" do - h = { a: 1 }.taint - h.reject {false}.tainted?.should == false + ruby_version_is ''...'2.7' do + it "does not taint the resulting hash" do + h = { a: 1 }.taint + h.reject {false}.tainted?.should == false + end end end diff --git a/spec/ruby/core/hash/shared/eql.rb b/spec/ruby/core/hash/shared/eql.rb index 1aed5f51fb..d8c33179fc 100644 --- a/spec/ruby/core/hash/shared/eql.rb +++ b/spec/ruby/core/hash/shared/eql.rb @@ -149,46 +149,80 @@ describe :hash_eql_additional, shared: true do h.send(@method, HashSpecs::MyHash[h]).should be_true end - # Why isn't this true of eql? too ? - it "compares keys with matching hash codes via eql?" do - a = Array.new(2) do - obj = mock('0') - obj.should_receive(:hash).at_least(1).and_return(0) - - # It's undefined whether the impl does a[0].eql?(a[1]) or - # a[1].eql?(a[0]) so we taint both. - def obj.eql?(o) - return true if self.equal?(o) - taint - o.taint - false + ruby_version_is '2.7' do + # Why isn't this true of eql? too ? + it "compares keys with matching hash codes via eql?" do + a = Array.new(2) do + obj = mock('0') + obj.should_receive(:hash).at_least(1).and_return(0) + + def obj.eql?(o) + return true if self.equal?(o) + false + end + + obj end - obj - end + { a[0] => 1 }.send(@method, { a[1] => 1 }).should be_false - { a[0] => 1 }.send(@method, { a[1] => 1 }).should be_false - a[0].tainted?.should be_true - a[1].tainted?.should be_true + a = Array.new(2) do + obj = mock('0') + obj.should_receive(:hash).at_least(1).and_return(0) - a = Array.new(2) do - obj = mock('0') - obj.should_receive(:hash).at_least(1).and_return(0) + def obj.eql?(o) + true + end - def obj.eql?(o) - # It's undefined whether the impl does a[0].send(@method, a[1]) or - # a[1].send(@method, a[0]) so we taint both. - taint - o.taint - true + obj end - obj + { a[0] => 1 }.send(@method, { a[1] => 1 }).should be_true end + end + + ruby_version_is ''...'2.7' do + # Why isn't this true of eql? too ? + it "compares keys with matching hash codes via eql?" do + a = Array.new(2) do + obj = mock('0') + obj.should_receive(:hash).at_least(1).and_return(0) + + # It's undefined whether the impl does a[0].eql?(a[1]) or + # a[1].eql?(a[0]) so we taint both. + def obj.eql?(o) + return true if self.equal?(o) + taint + o.taint + false + end + + obj + end - { a[0] => 1 }.send(@method, { a[1] => 1 }).should be_true - a[0].tainted?.should be_true - a[1].tainted?.should be_true + { a[0] => 1 }.send(@method, { a[1] => 1 }).should be_false + a[0].tainted?.should be_true + a[1].tainted?.should be_true + + a = Array.new(2) do + obj = mock('0') + obj.should_receive(:hash).at_least(1).and_return(0) + + def obj.eql?(o) + # It's undefined whether the impl does a[0].send(@method, a[1]) or + # a[1].send(@method, a[0]) so we taint both. + taint + o.taint + true + end + + obj + end + + { a[0] => 1 }.send(@method, { a[1] => 1 }).should be_true + a[0].tainted?.should be_true + a[1].tainted?.should be_true + end end it "compares the values in self to values in other hash" do diff --git a/spec/ruby/core/hash/shared/to_s.rb b/spec/ruby/core/hash/shared/to_s.rb index d180d08c2c..b0e3705d01 100644 --- a/spec/ruby/core/hash/shared/to_s.rb +++ b/spec/ruby/core/hash/shared/to_s.rb @@ -77,14 +77,16 @@ describe :hash_to_s, shared: true do y.send(@method).should == "{1=>{0=>{...}}}" end - it "returns a tainted string if self is tainted and not empty" do - {}.taint.send(@method).tainted?.should be_false - { nil => nil }.taint.send(@method).tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "returns a tainted string if self is tainted and not empty" do + {}.taint.send(@method).tainted?.should be_false + { nil => nil }.taint.send(@method).tainted?.should be_true + end - it "returns an untrusted string if self is untrusted and not empty" do - {}.untrust.send(@method).untrusted?.should be_false - { nil => nil }.untrust.send(@method).untrusted?.should be_true + it "returns an untrusted string if self is untrusted and not empty" do + {}.untrust.send(@method).untrusted?.should be_false + { nil => nil }.untrust.send(@method).untrusted?.should be_true + end end it "does not raise if inspected result is not default external encoding" do diff --git a/spec/ruby/core/hash/to_a_spec.rb b/spec/ruby/core/hash/to_a_spec.rb index 33ad7cdec9..46f871389a 100644 --- a/spec/ruby/core/hash/to_a_spec.rb +++ b/spec/ruby/core/hash/to_a_spec.rb @@ -27,11 +27,13 @@ describe "Hash#to_a" do ent.should == pairs end - it "returns a tainted array if self is tainted" do - {}.taint.to_a.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "returns a tainted array if self is tainted" do + {}.taint.to_a.tainted?.should be_true + end - it "returns an untrusted array if self is untrusted" do - {}.untrust.to_a.untrusted?.should be_true + it "returns an untrusted array if self is untrusted" do + {}.untrust.to_a.untrusted?.should be_true + end end end diff --git a/spec/ruby/core/io/gets_spec.rb b/spec/ruby/core/io/gets_spec.rb index 8f6ec0dfc7..39b2108476 100644 --- a/spec/ruby/core/io/gets_spec.rb +++ b/spec/ruby/core/io/gets_spec.rb @@ -38,9 +38,11 @@ describe "IO#gets" do IOSpecs.lines.each { |line| line.should == @io.gets } end - it "returns tainted strings" do - while line = @io.gets - line.tainted?.should == true + ruby_version_is ''...'2.7' do + it "returns tainted strings" do + while line = @io.gets + line.tainted?.should == true + end end end @@ -62,9 +64,11 @@ describe "IO#gets" do @io.gets(nil).should == IOSpecs.lines.join("") end - it "returns tainted strings" do - while line = @io.gets(nil) - line.tainted?.should == true + ruby_version_is ''...'2.7' do + it "returns tainted strings" do + while line = @io.gets(nil) + line.tainted?.should == true + end end end @@ -96,9 +100,11 @@ describe "IO#gets" do @io.gets.should == IOSpecs.lines[4] end - it "returns tainted strings" do - while line = @io.gets("") - line.tainted?.should == true + ruby_version_is ''...'2.7' do + it "returns tainted strings" do + while line = @io.gets("") + line.tainted?.should == true + end end end @@ -120,9 +126,11 @@ describe "IO#gets" do @io.gets("la linea").should == "Voici la ligne une.\nQui \303\250 la linea" end - it "returns tainted strings" do - while line = @io.gets("la") - line.tainted?.should == true + ruby_version_is ''...'2.7' do + it "returns tainted strings" do + while line = @io.gets("la") + line.tainted?.should == true + end end end diff --git a/spec/ruby/core/kernel/clone_spec.rb b/spec/ruby/core/kernel/clone_spec.rb index eb8739d571..f20ea618b5 100644 --- a/spec/ruby/core/kernel/clone_spec.rb +++ b/spec/ruby/core/kernel/clone_spec.rb @@ -108,9 +108,15 @@ describe "Kernel#clone" do cloned.bar.should == ['a'] end - it 'copies frozen? and tainted?' do - o = ''.taint.freeze.clone + it 'copies frozen?' do + o = ''.freeze.clone o.frozen?.should be_true - o.tainted?.should be_true + end + + ruby_version_is ''...'2.7' do + it 'copies tainted?' do + o = ''.taint.clone + o.tainted?.should be_true + end end end diff --git a/spec/ruby/core/kernel/inspect_spec.rb b/spec/ruby/core/kernel/inspect_spec.rb index b5ba1a3903..a946d032db 100644 --- a/spec/ruby/core/kernel/inspect_spec.rb +++ b/spec/ruby/core/kernel/inspect_spec.rb @@ -6,12 +6,14 @@ describe "Kernel#inspect" do Object.new.inspect.should be_an_instance_of(String) end - it "returns a tainted string if self is tainted" do - Object.new.taint.inspect.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "returns a tainted string if self is tainted" do + Object.new.taint.inspect.tainted?.should be_true + end - it "returns an untrusted string if self is untrusted" do - Object.new.untrust.inspect.untrusted?.should be_true + it "returns an untrusted string if self is untrusted" do + Object.new.untrust.inspect.untrusted?.should be_true + end end it "does not call #to_s if it is defined" do diff --git a/spec/ruby/core/kernel/shared/dup_clone.rb b/spec/ruby/core/kernel/shared/dup_clone.rb index d1ee64bd09..a52ccab359 100644 --- a/spec/ruby/core/kernel/shared/dup_clone.rb +++ b/spec/ruby/core/kernel/shared/dup_clone.rb @@ -52,14 +52,16 @@ describe :kernel_dup_clone, shared: true do o2.original.should equal(o) end - it "preserves tainted state from the original" do - o = ObjectSpecDupInitCopy.new - o2 = o.send(@method) - o.taint - o3 = o.send(@method) - - o2.tainted?.should == false - o3.tainted?.should == true + ruby_version_is ''...'2.7' do + it "preserves tainted state from the original" do + o = ObjectSpecDupInitCopy.new + o2 = o.send(@method) + o.taint + o3 = o.send(@method) + + o2.tainted?.should == false + o3.tainted?.should == true + end end it "does not preserve the object_id" do @@ -69,14 +71,16 @@ describe :kernel_dup_clone, shared: true do o2.object_id.should_not == old_object_id end - it "preserves untrusted state from the original" do - o = ObjectSpecDupInitCopy.new - o2 = o.send(@method) - o.untrust - o3 = o.send(@method) + ruby_version_is ''...'2.7' do + it "preserves untrusted state from the original" do + o = ObjectSpecDupInitCopy.new + o2 = o.send(@method) + o.untrust + o3 = o.send(@method) - o2.untrusted?.should == false - o3.untrusted?.should == true + o2.untrusted?.should == false + o3.untrusted?.should == true + end end it "returns nil for NilClass" do diff --git a/spec/ruby/core/kernel/taint_spec.rb b/spec/ruby/core/kernel/taint_spec.rb index 000295f6d2..6de009a46c 100644 --- a/spec/ruby/core/kernel/taint_spec.rb +++ b/spec/ruby/core/kernel/taint_spec.rb @@ -2,44 +2,46 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "Kernel#taint" do - it "returns self" do - o = Object.new - o.taint.should equal(o) - end - - it "sets the tainted bit" do - o = Object.new - o.taint - o.tainted?.should == true - end + ruby_version_is ''...'2.7' do + it "returns self" do + o = Object.new + o.taint.should equal(o) + end - it "raises #{frozen_error_class} on an untainted, frozen object" do - o = Object.new.freeze - -> { o.taint }.should raise_error(frozen_error_class) - end + it "sets the tainted bit" do + o = Object.new + o.taint + o.tainted?.should == true + end - it "does not raise an error on a tainted, frozen object" do - o = Object.new.taint.freeze - o.taint.should equal(o) - end + it "raises #{frozen_error_class} on an untainted, frozen object" do + o = Object.new.freeze + -> { o.taint }.should raise_error(frozen_error_class) + end - it "has no effect on immediate values" do - [nil, true, false].each do |v| - v.taint - v.tainted?.should == false + it "does not raise an error on a tainted, frozen object" do + o = Object.new.taint.freeze + o.taint.should equal(o) end - end - it "no raises a RuntimeError on symbols" do - v = :sym - -> { v.taint }.should_not raise_error(RuntimeError) - v.tainted?.should == false - end + it "has no effect on immediate values" do + [nil, true, false].each do |v| + v.taint + v.tainted?.should == false + end + end - it "no raises error on fixnum values" do - [1].each do |v| + it "no raises a RuntimeError on symbols" do + v = :sym -> { v.taint }.should_not raise_error(RuntimeError) v.tainted?.should == false end + + it "no raises error on fixnum values" do + [1].each do |v| + -> { v.taint }.should_not raise_error(RuntimeError) + v.tainted?.should == false + end + end end end diff --git a/spec/ruby/core/kernel/tainted_spec.rb b/spec/ruby/core/kernel/tainted_spec.rb index c024756110..72ce346dda 100644 --- a/spec/ruby/core/kernel/tainted_spec.rb +++ b/spec/ruby/core/kernel/tainted_spec.rb @@ -2,11 +2,13 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "Kernel#tainted?" do - it "returns true if Object is tainted" do - o = mock('o') - p = mock('p') - p.taint - o.tainted?.should == false - p.tainted?.should == true + ruby_version_is ''...'2.7' do + it "returns true if Object is tainted" do + o = mock('o') + p = mock('p') + p.taint + o.tainted?.should == false + p.tainted?.should == true + end end end diff --git a/spec/ruby/core/kernel/to_s_spec.rb b/spec/ruby/core/kernel/to_s_spec.rb index 4b59520ce7..64b40f46e5 100644 --- a/spec/ruby/core/kernel/to_s_spec.rb +++ b/spec/ruby/core/kernel/to_s_spec.rb @@ -6,11 +6,13 @@ describe "Kernel#to_s" do Object.new.to_s.should =~ /Object/ end - it "returns a tainted result if self is tainted" do - Object.new.taint.to_s.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "returns a tainted result if self is tainted" do + Object.new.taint.to_s.tainted?.should be_true + end - it "returns an untrusted result if self is untrusted" do - Object.new.untrust.to_s.untrusted?.should be_true + it "returns an untrusted result if self is untrusted" do + Object.new.untrust.to_s.untrusted?.should be_true + end end end diff --git a/spec/ruby/core/kernel/trust_spec.rb b/spec/ruby/core/kernel/trust_spec.rb index d34aa293ec..13f085f420 100644 --- a/spec/ruby/core/kernel/trust_spec.rb +++ b/spec/ruby/core/kernel/trust_spec.rb @@ -2,24 +2,26 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "Kernel#trust" do - it "returns self" do - o = Object.new - o.trust.should equal(o) - end + ruby_version_is ''...'2.7' do + it "returns self" do + o = Object.new + o.trust.should equal(o) + end - it "clears the untrusted bit" do - o = Object.new.untrust - o.trust - o.untrusted?.should == false - end + it "clears the untrusted bit" do + o = Object.new.untrust + o.trust + o.untrusted?.should == false + end - it "raises #{frozen_error_class} on an untrusted, frozen object" do - o = Object.new.untrust.freeze - -> { o.trust }.should raise_error(frozen_error_class) - end + it "raises #{frozen_error_class} on an untrusted, frozen object" do + o = Object.new.untrust.freeze + -> { o.trust }.should raise_error(frozen_error_class) + end - it "does not raise an error on a trusted, frozen object" do - o = Object.new.freeze - o.trust.should equal(o) + it "does not raise an error on a trusted, frozen object" do + o = Object.new.freeze + o.trust.should equal(o) + end end end diff --git a/spec/ruby/core/kernel/untaint_spec.rb b/spec/ruby/core/kernel/untaint_spec.rb index 94e4a8fd44..58485fcc58 100644 --- a/spec/ruby/core/kernel/untaint_spec.rb +++ b/spec/ruby/core/kernel/untaint_spec.rb @@ -2,24 +2,26 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "Kernel#untaint" do - it "returns self" do - o = Object.new - o.untaint.should equal(o) - end + ruby_version_is ''...'2.7' do + it "returns self" do + o = Object.new + o.untaint.should equal(o) + end - it "clears the tainted bit" do - o = Object.new.taint - o.untaint - o.tainted?.should == false - end + it "clears the tainted bit" do + o = Object.new.taint + o.untaint + o.tainted?.should == false + end - it "raises #{frozen_error_class} on a tainted, frozen object" do - o = Object.new.taint.freeze - -> { o.untaint }.should raise_error(frozen_error_class) - end + it "raises #{frozen_error_class} on a tainted, frozen object" do + o = Object.new.taint.freeze + -> { o.untaint }.should raise_error(frozen_error_class) + end - it "does not raise an error on an untainted, frozen object" do - o = Object.new.freeze - o.untaint.should equal(o) + it "does not raise an error on an untainted, frozen object" do + o = Object.new.freeze + o.untaint.should equal(o) + end end end diff --git a/spec/ruby/core/kernel/untrust_spec.rb b/spec/ruby/core/kernel/untrust_spec.rb index 2ee3dbb170..c6eb79af1c 100644 --- a/spec/ruby/core/kernel/untrust_spec.rb +++ b/spec/ruby/core/kernel/untrust_spec.rb @@ -2,24 +2,26 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "Kernel#untrust" do - it "returns self" do - o = Object.new - o.untrust.should equal(o) - end + ruby_version_is ''...'2.7' do + it "returns self" do + o = Object.new + o.untrust.should equal(o) + end - it "sets the untrusted bit" do - o = Object.new - o.untrust - o.untrusted?.should == true - end + it "sets the untrusted bit" do + o = Object.new + o.untrust + o.untrusted?.should == true + end - it "raises #{frozen_error_class} on a trusted, frozen object" do - o = Object.new.freeze - -> { o.untrust }.should raise_error(frozen_error_class) - end + it "raises #{frozen_error_class} on a trusted, frozen object" do + o = Object.new.freeze + -> { o.untrust }.should raise_error(frozen_error_class) + end - it "does not raise an error on an untrusted, frozen object" do - o = Object.new.untrust.freeze - o.untrust.should equal(o) + it "does not raise an error on an untrusted, frozen object" do + o = Object.new.untrust.freeze + o.untrust.should equal(o) + end end end diff --git a/spec/ruby/core/kernel/untrusted_spec.rb b/spec/ruby/core/kernel/untrusted_spec.rb index 3f894b0bab..ccebfe38be 100644 --- a/spec/ruby/core/kernel/untrusted_spec.rb +++ b/spec/ruby/core/kernel/untrusted_spec.rb @@ -2,27 +2,29 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "Kernel#untrusted?" do - it "returns the untrusted status of an object" do - o = mock('o') - o.untrusted?.should == false - o.untrust - o.untrusted?.should == true - end + ruby_version_is ''...'2.7' do + it "returns the untrusted status of an object" do + o = mock('o') + o.untrusted?.should == false + o.untrust + o.untrusted?.should == true + end - it "has no effect on immediate values" do - a = nil - b = true - c = false - a.untrust - b.untrust - c.untrust - a.untrusted?.should == false - b.untrusted?.should == false - c.untrusted?.should == false - end + it "has no effect on immediate values" do + a = nil + b = true + c = false + a.untrust + b.untrust + c.untrust + a.untrusted?.should == false + b.untrusted?.should == false + c.untrusted?.should == false + end - it "has effect on immediate values" do - d = 1 - -> { d.untrust }.should_not raise_error(RuntimeError) + it "has effect on immediate values" do + d = 1 + -> { d.untrust }.should_not raise_error(RuntimeError) + end end end diff --git a/spec/ruby/core/marshal/dump_spec.rb b/spec/ruby/core/marshal/dump_spec.rb index 700f090a2f..3a7a083dd8 100644 --- a/spec/ruby/core/marshal/dump_spec.rb +++ b/spec/ruby/core/marshal/dump_spec.rb @@ -581,27 +581,29 @@ describe "Marshal.dump" do -> { Marshal.dump(m) }.should raise_error(TypeError) end - it "returns an untainted string if object is untainted" do - Marshal.dump(Object.new).tainted?.should be_false - end + ruby_version_is ''...'2.7' do + it "returns an untainted string if object is untainted" do + Marshal.dump(Object.new).tainted?.should be_false + end - it "returns a tainted string if object is tainted" do - Marshal.dump(Object.new.taint).tainted?.should be_true - end + it "returns a tainted string if object is tainted" do + Marshal.dump(Object.new.taint).tainted?.should be_true + end - it "returns a tainted string if nested object is tainted" do - Marshal.dump([[Object.new.taint]]).tainted?.should be_true - end + it "returns a tainted string if nested object is tainted" do + Marshal.dump([[Object.new.taint]]).tainted?.should be_true + end - it "returns a trusted string if object is trusted" do - Marshal.dump(Object.new).untrusted?.should be_false - end + it "returns a trusted string if object is trusted" do + Marshal.dump(Object.new).untrusted?.should be_false + end - it "returns an untrusted string if object is untrusted" do - Marshal.dump(Object.new.untrust).untrusted?.should be_true - end + it "returns an untrusted string if object is untrusted" do + Marshal.dump(Object.new.untrust).untrusted?.should be_true + end - it "returns an untrusted string if nested object is untrusted" do - Marshal.dump([[Object.new.untrust]]).untrusted?.should be_true + it "returns an untrusted string if nested object is untrusted" do + Marshal.dump([[Object.new.untrust]]).untrusted?.should be_true + end end end diff --git a/spec/ruby/core/marshal/shared/load.rb b/spec/ruby/core/marshal/shared/load.rb index f92d49c68c..b90a6a99ce 100644 --- a/spec/ruby/core/marshal/shared/load.rb +++ b/spec/ruby/core/marshal/shared/load.rb @@ -182,85 +182,87 @@ describe :marshal_load, shared: true do end end - it "returns an untainted object if source is untainted" do - x = Object.new - y = Marshal.send(@method, Marshal.dump(x)) - y.tainted?.should be_false - end - - describe "when source is tainted" do - it "returns a tainted object" do + ruby_version_is ''...'2.7' do + it "returns an untainted object if source is untainted" do x = Object.new - x.taint - s = Marshal.dump(x) - y = Marshal.send(@method, s) - y.tainted?.should be_true + y = Marshal.send(@method, Marshal.dump(x)) + y.tainted?.should be_false + end + + describe "when source is tainted" do + it "returns a tainted object" do + x = Object.new + x.taint + s = Marshal.dump(x) + y = Marshal.send(@method, s) + y.tainted?.should be_true + + # note that round-trip via Marshal does not preserve + # the taintedness at each level of the nested structure + y = Marshal.send(@method, Marshal.dump([[x]])) + y.tainted?.should be_true + y.first.tainted?.should be_true + y.first.first.tainted?.should be_true + end - # note that round-trip via Marshal does not preserve - # the taintedness at each level of the nested structure - y = Marshal.send(@method, Marshal.dump([[x]])) - y.tainted?.should be_true - y.first.tainted?.should be_true - y.first.first.tainted?.should be_true - end + it "does not taint Symbols" do + x = [:x] + y = Marshal.send(@method, Marshal.dump(x).taint) + y.tainted?.should be_true + y.first.tainted?.should be_false + end - it "does not taint Symbols" do - x = [:x] - y = Marshal.send(@method, Marshal.dump(x).taint) - y.tainted?.should be_true - y.first.tainted?.should be_false - end + it "does not taint Fixnums" do + x = [1] + y = Marshal.send(@method, Marshal.dump(x).taint) + y.tainted?.should be_true + y.first.tainted?.should be_false + end - it "does not taint Fixnums" do - x = [1] - y = Marshal.send(@method, Marshal.dump(x).taint) - y.tainted?.should be_true - y.first.tainted?.should be_false - end + it "does not taint Bignums" do + x = [bignum_value] + y = Marshal.send(@method, Marshal.dump(x).taint) + y.tainted?.should be_true + y.first.tainted?.should be_false + end - it "does not taint Bignums" do - x = [bignum_value] - y = Marshal.send(@method, Marshal.dump(x).taint) - y.tainted?.should be_true - y.first.tainted?.should be_false + it "does not taint Floats" do + x = [1.2] + y = Marshal.send(@method, Marshal.dump(x).taint) + y.tainted?.should be_true + y.first.tainted?.should be_false + end end - it "does not taint Floats" do - x = [1.2] - y = Marshal.send(@method, Marshal.dump(x).taint) + it "preserves taintedness of nested structure" do + x = Object.new + a = [[x]] + x.taint + y = Marshal.send(@method, Marshal.dump(a)) y.tainted?.should be_true - y.first.tainted?.should be_false + y.first.tainted?.should be_true + y.first.first.tainted?.should be_true end - end - it "preserves taintedness of nested structure" do - x = Object.new - a = [[x]] - x.taint - y = Marshal.send(@method, Marshal.dump(a)) - y.tainted?.should be_true - y.first.tainted?.should be_true - y.first.first.tainted?.should be_true - end - - it "returns a trusted object if source is trusted" do - x = Object.new - y = Marshal.send(@method, Marshal.dump(x)) - y.untrusted?.should be_false - end + it "returns a trusted object if source is trusted" do + x = Object.new + y = Marshal.send(@method, Marshal.dump(x)) + y.untrusted?.should be_false + end - it "returns an untrusted object if source is untrusted" do - x = Object.new - x.untrust - y = Marshal.send(@method, Marshal.dump(x)) - y.untrusted?.should be_true + it "returns an untrusted object if source is untrusted" do + x = Object.new + x.untrust + y = Marshal.send(@method, Marshal.dump(x)) + y.untrusted?.should be_true - # note that round-trip via Marshal does not preserve - # the untrustedness at each level of the nested structure - y = Marshal.send(@method, Marshal.dump([[x]])) - y.untrusted?.should be_true - y.first.untrusted?.should be_true - y.first.first.untrusted?.should be_true + # note that round-trip via Marshal does not preserve + # the untrustedness at each level of the nested structure + y = Marshal.send(@method, Marshal.dump([[x]])) + y.untrusted?.should be_true + y.first.untrusted?.should be_true + y.first.first.untrusted?.should be_true + end end # Note: Ruby 1.9 should be compatible with older marshal format diff --git a/spec/ruby/core/matchdata/post_match_spec.rb b/spec/ruby/core/matchdata/post_match_spec.rb index 6e13438124..4ae51f107e 100644 --- a/spec/ruby/core/matchdata/post_match_spec.rb +++ b/spec/ruby/core/matchdata/post_match_spec.rb @@ -6,20 +6,22 @@ describe "MatchData#post_match" do $'.should == ': The Movie' end - it "keeps taint status from the source string" do - str = "THX1138: The Movie" - str.taint - res = /(.)(.)(\d+)(\d)/.match(str).post_match - res.tainted?.should be_true - $'.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "keeps taint status from the source string" do + str = "THX1138: The Movie" + str.taint + res = /(.)(.)(\d+)(\d)/.match(str).post_match + res.tainted?.should be_true + $'.tainted?.should be_true + end - it "keeps untrusted status from the source string" do - str = "THX1138: The Movie" - str.untrust - res = /(.)(.)(\d+)(\d)/.match(str).post_match - res.untrusted?.should be_true - $'.untrusted?.should be_true + it "keeps untrusted status from the source string" do + str = "THX1138: The Movie" + str.untrust + res = /(.)(.)(\d+)(\d)/.match(str).post_match + res.untrusted?.should be_true + $'.untrusted?.should be_true + end end it "sets the encoding to the encoding of the source String" do diff --git a/spec/ruby/core/matchdata/pre_match_spec.rb b/spec/ruby/core/matchdata/pre_match_spec.rb index 816cc91eb2..824612c84c 100644 --- a/spec/ruby/core/matchdata/pre_match_spec.rb +++ b/spec/ruby/core/matchdata/pre_match_spec.rb @@ -6,20 +6,22 @@ describe "MatchData#pre_match" do $`.should == 'T' end - it "keeps taint status from the source string" do - str = "THX1138: The Movie" - str.taint - res = /(.)(.)(\d+)(\d)/.match(str).pre_match - res.tainted?.should be_true - $`.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "keeps taint status from the source string" do + str = "THX1138: The Movie" + str.taint + res = /(.)(.)(\d+)(\d)/.match(str).pre_match + res.tainted?.should be_true + $`.tainted?.should be_true + end - it "keeps untrusted status from the source string" do - str = "THX1138: The Movie" - str.untrust - res = /(.)(.)(\d+)(\d)/.match(str).pre_match - res.untrusted?.should be_true - $`.untrusted?.should be_true + it "keeps untrusted status from the source string" do + str = "THX1138: The Movie" + str.untrust + res = /(.)(.)(\d+)(\d)/.match(str).pre_match + res.untrusted?.should be_true + $`.untrusted?.should be_true + end end it "sets the encoding to the encoding of the source String" do diff --git a/spec/ruby/core/module/append_features_spec.rb b/spec/ruby/core/module/append_features_spec.rb index 584aa11dfa..8fb3febc04 100644 --- a/spec/ruby/core/module/append_features_spec.rb +++ b/spec/ruby/core/module/append_features_spec.rb @@ -47,16 +47,18 @@ describe "Module#append_features" do end - it "copies own tainted status to the given module" do - other = Module.new - Module.new.taint.send :append_features, other - other.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "copies own tainted status to the given module" do + other = Module.new + Module.new.taint.send :append_features, other + other.tainted?.should be_true + end - it "copies own untrusted status to the given module" do - other = Module.new - Module.new.untrust.send :append_features, other - other.untrusted?.should be_true + it "copies own untrusted status to the given module" do + other = Module.new + Module.new.untrust.send :append_features, other + other.untrusted?.should be_true + end end describe "when other is frozen" do diff --git a/spec/ruby/core/module/extend_object_spec.rb b/spec/ruby/core/module/extend_object_spec.rb index bc97a55e7c..e66b87efef 100644 --- a/spec/ruby/core/module/extend_object_spec.rb +++ b/spec/ruby/core/module/extend_object_spec.rb @@ -42,16 +42,18 @@ describe "Module#extend_object" do ScratchPad.recorded.should == :extended end - it "does not copy own tainted status to the given object" do - other = Object.new - Module.new.taint.send :extend_object, other - other.tainted?.should be_false - end + ruby_version_is ''...'2.7' do + it "does not copy own tainted status to the given object" do + other = Object.new + Module.new.taint.send :extend_object, other + other.tainted?.should be_false + end - it "does not copy own untrusted status to the given object" do - other = Object.new - Module.new.untrust.send :extend_object, other - other.untrusted?.should be_false + it "does not copy own untrusted status to the given object" do + other = Object.new + Module.new.untrust.send :extend_object, other + other.untrusted?.should be_false + end end describe "when given a frozen object" do diff --git a/spec/ruby/core/module/prepend_features_spec.rb b/spec/ruby/core/module/prepend_features_spec.rb index b6fce9aba0..2d1fa713b7 100644 --- a/spec/ruby/core/module/prepend_features_spec.rb +++ b/spec/ruby/core/module/prepend_features_spec.rb @@ -28,16 +28,18 @@ describe "Module#prepend_features" do }.should raise_error(ArgumentError) end - it "copies own tainted status to the given module" do - other = Module.new - Module.new.taint.send :prepend_features, other - other.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "copies own tainted status to the given module" do + other = Module.new + Module.new.taint.send :prepend_features, other + other.tainted?.should be_true + end - it "copies own untrusted status to the given module" do - other = Module.new - Module.new.untrust.send :prepend_features, other - other.untrusted?.should be_true + it "copies own untrusted status to the given module" do + other = Module.new + Module.new.untrust.send :prepend_features, other + other.untrusted?.should be_true + end end it "clears caches of the given module" do diff --git a/spec/ruby/core/range/inspect_spec.rb b/spec/ruby/core/range/inspect_spec.rb index 3c130812d0..837f7e69ab 100644 --- a/spec/ruby/core/range/inspect_spec.rb +++ b/spec/ruby/core/range/inspect_spec.rb @@ -12,15 +12,17 @@ describe "Range#inspect" do (0.5..2.4).inspect.should == "0.5..2.4" end - it "returns a tainted string if either end is tainted" do - (("a".taint)..."c").inspect.tainted?.should be_true - ("a"...("c".taint)).inspect.tainted?.should be_true - ("a"..."c").taint.inspect.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "returns a tainted string if either end is tainted" do + (("a".taint)..."c").inspect.tainted?.should be_true + ("a"...("c".taint)).inspect.tainted?.should be_true + ("a"..."c").taint.inspect.tainted?.should be_true + end - it "returns a untrusted string if either end is untrusted" do - (("a".untrust)..."c").inspect.untrusted?.should be_true - ("a"...("c".untrust)).inspect.untrusted?.should be_true - ("a"..."c").untrust.inspect.untrusted?.should be_true + it "returns a untrusted string if either end is untrusted" do + (("a".untrust)..."c").inspect.untrusted?.should be_true + ("a"...("c".untrust)).inspect.untrusted?.should be_true + ("a"..."c").untrust.inspect.untrusted?.should be_true + end end end diff --git a/spec/ruby/core/range/to_s_spec.rb b/spec/ruby/core/range/to_s_spec.rb index 4c37e81fe0..7392aa9890 100644 --- a/spec/ruby/core/range/to_s_spec.rb +++ b/spec/ruby/core/range/to_s_spec.rb @@ -11,15 +11,17 @@ describe "Range#to_s" do (0.5..2.4).to_s.should == "0.5..2.4" end - it "returns a tainted string if either end is tainted" do - (("a".taint)..."c").to_s.tainted?.should be_true - ("a"...("c".taint)).to_s.tainted?.should be_true - ("a"..."c").taint.to_s.tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "returns a tainted string if either end is tainted" do + (("a".taint)..."c").to_s.tainted?.should be_true + ("a"...("c".taint)).to_s.tainted?.should be_true + ("a"..."c").taint.to_s.tainted?.should be_true + end - it "returns a untrusted string if either end is untrusted" do - (("a".untrust)..."c").to_s.untrusted?.should be_true - ("a"...("c".untrust)).to_s.untrusted?.should be_true - ("a"..."c").untrust.to_s.untrusted?.should be_true + it "returns a untrusted string if either end is untrusted" do + (("a".untrust)..."c").to_s.untrusted?.should be_true + ("a"...("c".untrust)).to_s.untrusted?.should be_true + ("a"..."c").untrust.to_s.untrusted?.should be_true + end end end diff --git a/spec/ruby/core/string/b_spec.rb b/spec/ruby/core/string/b_spec.rb index b43cb5393a..b2e3d326ba 100644 --- a/spec/ruby/core/string/b_spec.rb +++ b/spec/ruby/core/string/b_spec.rb @@ -13,10 +13,12 @@ describe "String#b" do str.should == "こんちには" end - it "copies own tainted/untrusted status to the returning value" do - utf_8 = "こんちには".taint.untrust - ret = utf_8.b - ret.tainted?.should be_true - ret.untrusted?.should be_true + ruby_version_is ''...'2.7' do + it "copies own tainted/untrusted status to the returning value" do + utf_8 = "こんちには".taint.untrust + ret = utf_8.b + ret.tainted?.should be_true + ret.untrusted?.should be_true + end end end diff --git a/spec/ruby/core/string/capitalize_spec.rb b/spec/ruby/core/string/capitalize_spec.rb index df64cdaa3b..41dd63f63e 100644 --- a/spec/ruby/core/string/capitalize_spec.rb +++ b/spec/ruby/core/string/capitalize_spec.rb @@ -12,9 +12,11 @@ describe "String#capitalize" do "123ABC".capitalize.should == "123abc" end - it "taints resulting string when self is tainted" do - "".taint.capitalize.tainted?.should == true - "hello".taint.capitalize.tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints resulting string when self is tainted" do + "".taint.capitalize.tainted?.should == true + "hello".taint.capitalize.tainted?.should == true + end end describe "full Unicode case mapping" do diff --git a/spec/ruby/core/string/center_spec.rb b/spec/ruby/core/string/center_spec.rb index 27f8b7387f..0284fc28dc 100644 --- a/spec/ruby/core/string/center_spec.rb +++ b/spec/ruby/core/string/center_spec.rb @@ -47,12 +47,14 @@ describe "String#center with length, padding" do "radiology".center(8, '-').should == "radiology" end - it "taints result when self or padstr is tainted" do - "x".taint.center(4).tainted?.should == true - "x".taint.center(0).tainted?.should == true - "".taint.center(0).tainted?.should == true - "x".taint.center(4, "*").tainted?.should == true - "x".center(4, "*".taint).tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints result when self or padstr is tainted" do + "x".taint.center(4).tainted?.should == true + "x".taint.center(0).tainted?.should == true + "".taint.center(0).tainted?.should == true + "x".taint.center(4, "*").tainted?.should == true + "x".center(4, "*".taint).tainted?.should == true + end end it "calls #to_int to convert length to an integer" do @@ -98,10 +100,12 @@ describe "String#center with length, padding" do "foo".center(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) end - it "when padding is tainted and self is untainted returns a tainted string if and only if length is longer than self" do - "hello".center(4, 'X'.taint).tainted?.should be_false - "hello".center(5, 'X'.taint).tainted?.should be_false - "hello".center(6, 'X'.taint).tainted?.should be_true + ruby_version_is ''...'2.7' do + it "when padding is tainted and self is untainted returns a tainted string if and only if length is longer than self" do + "hello".center(4, 'X'.taint).tainted?.should be_false + "hello".center(5, 'X'.taint).tainted?.should be_false + "hello".center(6, 'X'.taint).tainted?.should be_true + end end describe "with width" do diff --git a/spec/ruby/core/string/chomp_spec.rb b/spec/ruby/core/string/chomp_spec.rb index 9db47d1dc6..20a0925959 100644 --- a/spec/ruby/core/string/chomp_spec.rb +++ b/spec/ruby/core/string/chomp_spec.rb @@ -38,8 +38,10 @@ describe "String#chomp" do "".chomp.should == "" end - it "taints the result if self is tainted" do - "abc".taint.chomp.tainted?.should be_true + ruby_version_is ''...'2.7' do + it "taints the result if self is tainted" do + "abc".taint.chomp.tainted?.should be_true + end end it "returns subclass instances when called on a subclass" do @@ -63,8 +65,10 @@ describe "String#chomp" do str.chomp(nil).should_not equal(str) end - it "taints the result if self is tainted" do - "abc".taint.chomp(nil).tainted?.should be_true + ruby_version_is ''...'2.7' do + it "taints the result if self is tainted" do + "abc".taint.chomp(nil).tainted?.should be_true + end end it "returns an empty String when self is empty" do @@ -93,8 +97,10 @@ describe "String#chomp" do "abc\r\n\r\n\r\n".chomp("").should == "abc" end - it "taints the result if self is tainted" do - "abc".taint.chomp("").tainted?.should be_true + ruby_version_is ''...'2.7' do + it "taints the result if self is tainted" do + "abc".taint.chomp("").tainted?.should be_true + end end it "returns an empty String when self is empty" do @@ -115,8 +121,10 @@ describe "String#chomp" do "abc\r\n\r\n".chomp("\n").should == "abc\r\n" end - it "taints the result if self is tainted" do - "abc".taint.chomp("\n").tainted?.should be_true + ruby_version_is ''...'2.7' do + it "taints the result if self is tainted" do + "abc".taint.chomp("\n").tainted?.should be_true + end end it "returns an empty String when self is empty" do @@ -151,12 +159,14 @@ describe "String#chomp" do "".chomp("abc").should == "" end - it "taints the result if self is tainted" do - "abc".taint.chomp("abc").tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "taints the result if self is tainted" do + "abc".taint.chomp("abc").tainted?.should be_true + end - it "does not taint the result when the argument is tainted" do - "abc".chomp("abc".taint).tainted?.should be_false + it "does not taint the result when the argument is tainted" do + "abc".chomp("abc".taint).tainted?.should be_false + end end it "returns an empty String when the argument equals self" do @@ -201,8 +211,10 @@ describe "String#chomp!" do "".chomp!.should be_nil end - it "taints the result if self is tainted" do - "abc\n".taint.chomp!.tainted?.should be_true + ruby_version_is ''...'2.7' do + it "taints the result if self is tainted" do + "abc\n".taint.chomp!.tainted?.should be_true + end end it "returns subclass instances when called on a subclass" do @@ -247,8 +259,10 @@ describe "String#chomp!" do "abc\r\n\r\n\r\n".chomp!("").should == "abc" end - it "taints the result if self is tainted" do - "abc\n".taint.chomp!("").tainted?.should be_true + ruby_version_is ''...'2.7' do + it "taints the result if self is tainted" do + "abc\n".taint.chomp!("").tainted?.should be_true + end end it "returns nil when self is empty" do @@ -269,8 +283,10 @@ describe "String#chomp!" do "abc\r\n\r\n".chomp!("\n").should == "abc\r\n" end - it "taints the result if self is tainted" do - "abc\n".taint.chomp!("\n").tainted?.should be_true + ruby_version_is ''...'2.7' do + it "taints the result if self is tainted" do + "abc\n".taint.chomp!("\n").tainted?.should be_true + end end it "returns nil when self is empty" do @@ -305,12 +321,14 @@ describe "String#chomp!" do "".chomp!("abc").should be_nil end - it "taints the result if self is tainted" do - "abc".taint.chomp!("abc").tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "taints the result if self is tainted" do + "abc".taint.chomp!("abc").tainted?.should be_true + end - it "does not taint the result when the argument is tainted" do - "abc".chomp!("abc".taint).tainted?.should be_false + it "does not taint the result when the argument is tainted" do + "abc".chomp!("abc".taint).tainted?.should be_false + end end end diff --git a/spec/ruby/core/string/chop_spec.rb b/spec/ruby/core/string/chop_spec.rb index 35a5766b2f..9e893c3bea 100644 --- a/spec/ruby/core/string/chop_spec.rb +++ b/spec/ruby/core/string/chop_spec.rb @@ -49,14 +49,16 @@ describe "String#chop" do s.chop.should_not equal(s) end - it "taints result when self is tainted" do - "hello".taint.chop.tainted?.should == true - "".taint.chop.tainted?.should == true - end - - it "untrusts result when self is untrusted" do - "hello".untrust.chop.untrusted?.should == true - "".untrust.chop.untrusted?.should == true + ruby_version_is ''...'2.7' do + it "taints result when self is tainted" do + "hello".taint.chop.tainted?.should == true + "".taint.chop.tainted?.should == true + end + + it "untrusts result when self is untrusted" do + "hello".untrust.chop.untrusted?.should == true + "".untrust.chop.untrusted?.should == true + end end it "returns subclass instances when called on a subclass" do diff --git a/spec/ruby/core/string/crypt_spec.rb b/spec/ruby/core/string/crypt_spec.rb index 7a0f8835f2..6a9a4ae235 100644 --- a/spec/ruby/core/string/crypt_spec.rb +++ b/spec/ruby/core/string/crypt_spec.rb @@ -25,17 +25,19 @@ describe "String#crypt" do "mypassword".crypt(obj).should == "$2a$04$0WVaz0pV3jzfZ5G5tpmHWuBQGbkjzgtSc3gJbmdy0GAGMa45MFM2." end - it "taints the result if either salt or self is tainted" do - tainted_salt = "$2a$04$0WVaz0pV3jzfZ5G5tpmHWu" - tainted_str = "mypassword" - - tainted_salt.taint - tainted_str.taint - - "mypassword".crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu").tainted?.should == false - tainted_str.crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu").tainted?.should == true - "mypassword".crypt(tainted_salt).tainted?.should == true - tainted_str.crypt(tainted_salt).tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints the result if either salt or self is tainted" do + tainted_salt = "$2a$04$0WVaz0pV3jzfZ5G5tpmHWu" + tainted_str = "mypassword" + + tainted_salt.taint + tainted_str.taint + + "mypassword".crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu").tainted?.should == false + tainted_str.crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu").tainted?.should == true + "mypassword".crypt(tainted_salt).tainted?.should == true + tainted_str.crypt(tainted_salt).tainted?.should == true + end end it "doesn't return subclass instances" do @@ -83,17 +85,19 @@ describe "String#crypt" do "".crypt(obj).should == "aaQSqAReePlq6" end - it "taints the result if either salt or self is tainted" do - tainted_salt = "aa" - tainted_str = "hello" + ruby_version_is ''...'2.7' do + it "taints the result if either salt or self is tainted" do + tainted_salt = "aa" + tainted_str = "hello" - tainted_salt.taint - tainted_str.taint + tainted_salt.taint + tainted_str.taint - "hello".crypt("aa").tainted?.should == false - tainted_str.crypt("aa").tainted?.should == true - "hello".crypt(tainted_salt).tainted?.should == true - tainted_str.crypt(tainted_salt).tainted?.should == true + "hello".crypt("aa").tainted?.should == false + tainted_str.crypt("aa").tainted?.should == true + "hello".crypt(tainted_salt).tainted?.should == true + tainted_str.crypt(tainted_salt).tainted?.should == true + end end it "doesn't return subclass instances" do diff --git a/spec/ruby/core/string/delete_prefix_spec.rb b/spec/ruby/core/string/delete_prefix_spec.rb index b88c503658..92c301b44a 100644 --- a/spec/ruby/core/string/delete_prefix_spec.rb +++ b/spec/ruby/core/string/delete_prefix_spec.rb @@ -22,9 +22,11 @@ ruby_version_is '2.5' do r.should == s end - it "taints resulting strings when other is tainted" do - 'hello'.taint.delete_prefix('hell').tainted?.should == true - 'hello'.taint.delete_prefix('').tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints resulting strings when other is tainted" do + 'hello'.taint.delete_prefix('hell').tainted?.should == true + 'hello'.taint.delete_prefix('').tainted?.should == true + end end it "doesn't set $~" do diff --git a/spec/ruby/core/string/delete_spec.rb b/spec/ruby/core/string/delete_spec.rb index 6136cd54af..130228041e 100644 --- a/spec/ruby/core/string/delete_spec.rb +++ b/spec/ruby/core/string/delete_spec.rb @@ -68,11 +68,13 @@ describe "String#delete" do -> { "hello".delete("^h-e") }.should raise_error(ArgumentError) end - it "taints result when self is tainted" do - "hello".taint.delete("e").tainted?.should == true - "hello".taint.delete("a-z").tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints result when self is tainted" do + "hello".taint.delete("e").tainted?.should == true + "hello".taint.delete("a-z").tainted?.should == true - "hello".delete("e".taint).tainted?.should == false + "hello".delete("e".taint).tainted?.should == false + end end it "tries to convert each set arg to a string using to_str" do diff --git a/spec/ruby/core/string/delete_suffix_spec.rb b/spec/ruby/core/string/delete_suffix_spec.rb index 94909cf71d..edc0f73158 100644 --- a/spec/ruby/core/string/delete_suffix_spec.rb +++ b/spec/ruby/core/string/delete_suffix_spec.rb @@ -22,9 +22,11 @@ ruby_version_is '2.5' do r.should == s end - it "taints resulting strings when other is tainted" do - 'hello'.taint.delete_suffix('ello').tainted?.should == true - 'hello'.taint.delete_suffix('').tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints resulting strings when other is tainted" do + 'hello'.taint.delete_suffix('ello').tainted?.should == true + 'hello'.taint.delete_suffix('').tainted?.should == true + end end it "doesn't set $~" do diff --git a/spec/ruby/core/string/downcase_spec.rb b/spec/ruby/core/string/downcase_spec.rb index 31c8f3f446..84e94ee104 100644 --- a/spec/ruby/core/string/downcase_spec.rb +++ b/spec/ruby/core/string/downcase_spec.rb @@ -68,10 +68,12 @@ describe "String#downcase" do -> { "ABC".downcase(:invalid_option) }.should raise_error(ArgumentError) end - it "taints result when self is tainted" do - "".taint.downcase.tainted?.should == true - "x".taint.downcase.tainted?.should == true - "X".taint.downcase.tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints result when self is tainted" do + "".taint.downcase.tainted?.should == true + "x".taint.downcase.tainted?.should == true + "X".taint.downcase.tainted?.should == true + end end it "returns a subclass instance for subclasses" do diff --git a/spec/ruby/core/string/dump_spec.rb b/spec/ruby/core/string/dump_spec.rb index 95eb9aa874..260ee37adb 100644 --- a/spec/ruby/core/string/dump_spec.rb +++ b/spec/ruby/core/string/dump_spec.rb @@ -3,14 +3,16 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "String#dump" do - it "taints the result if self is tainted" do - "foo".taint.dump.tainted?.should == true - "foo\n".taint.dump.tainted?.should == true - end + ruby_version_is ''...'2.7' do + it "taints the result if self is tainted" do + "foo".taint.dump.tainted?.should == true + "foo\n".taint.dump.tainted?.should == true + end - it "untrusts the result if self is untrusted" do - "foo".untrust.dump.untrusted?.should == true - "foo\n".untrust.dump.untrusted?.should == true + it "untrusts the result if self is untrusted" do + "foo".untrust.dump.untrusted?.should == true + "foo\n".untrust.dump.untrusted?.should == true + end end it "does not take into account if a string is frozen" do diff --git a/spec/ruby/core/string/element_set_spec.rb b/spec/ruby/core/string/element_set_spec.rb index 34e122b055..608efc23b3 100644 --- a/spec/ruby/core/string/element_set_spec.rb +++ b/spec/ruby/core/string/element_set_spec.rb @@ -14,14 +14,16 @@ describe "String#[]= with Fixnum index" do a.should == "bamelo" end - it "taints self if other_str is tainted" do - a = "hello" - a[0] = "".taint - a.tainted?.should == true - - a = "hello" - a[0] = "x".taint - a.tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints self if other_str is tainted" do + a = "hello" + a[0] = "".taint + a.tainted?.should == true + + a = "hello" + a[0] = "x".taint + a.tainted?.should == true + end end it "raises an IndexError without changing self if idx is outside of self" do @@ -485,14 +487,16 @@ describe "String#[]= with Fixnum index, count" do a.should == "hellobob" end - it "taints self if other_str is tainted" do - a = "hello" - a[0, 0] = "".taint - a.tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints self if other_str is tainted" do + a = "hello" + a[0, 0] = "".taint + a.tainted?.should == true - a = "hello" - a[1, 4] = "x".taint - a.tainted?.should == true + a = "hello" + a[1, 4] = "x".taint + a.tainted?.should == true + end end it "calls #to_int to convert the index and count objects" do diff --git a/spec/ruby/core/string/gsub_spec.rb b/spec/ruby/core/string/gsub_spec.rb index cd66a4f875..f1d2d5ac06 100644 --- a/spec/ruby/core/string/gsub_spec.rb +++ b/spec/ruby/core/string/gsub_spec.rb @@ -160,24 +160,26 @@ describe "String#gsub with pattern and replacement" do it_behaves_like :string_gsub_named_capture, :gsub - it "taints the result if the original string or replacement is tainted" do - hello = "hello" - hello_t = "hello" - a = "a" - a_t = "a" - empty = "" - empty_t = "" + ruby_version_is ''...'2.7' do + it "taints the result if the original string or replacement is tainted" do + hello = "hello" + hello_t = "hello" + a = "a" + a_t = "a" + empty = "" + empty_t = "" - hello_t.taint; a_t.taint; empty_t.taint + hello_t.taint; a_t.taint; empty_t.taint - hello_t.gsub(/./, a).tainted?.should == true - hello_t.gsub(/./, empty).tainted?.should == true + hello_t.gsub(/./, a).tainted?.should == true + hello_t.gsub(/./, empty).tainted?.should == true - hello.gsub(/./, a_t).tainted?.should == true - hello.gsub(/./, empty_t).tainted?.should == true - hello.gsub(//, empty_t).tainted?.should == true + hello.gsub(/./, a_t).tainted?.should == true + hello.gsub(/./, empty_t).tainted?.should == true + hello.gsub(//, empty_t).tainted?.should == true - hello.gsub(//.taint, "foo").tainted?.should == false + hello.gsub(//.taint, "foo").tainted?.should == false + end end it "handles pattern collapse" do @@ -186,24 +188,26 @@ describe "String#gsub with pattern and replacement" do str.gsub(reg, ".").should == ".こ.に.ち.わ." end - it "untrusts the result if the original string or replacement is untrusted" do - hello = "hello" - hello_t = "hello" - a = "a" - a_t = "a" - empty = "" - empty_t = "" + ruby_version_is ''...'2.7' do + it "untrusts the result if the original string or replacement is untrusted" do + hello = "hello" + hello_t = "hello" + a = "a" + a_t = "a" + empty = "" + empty_t = "" - hello_t.untrust; a_t.untrust; empty_t.untrust + hello_t.untrust; a_t.untrust; empty_t.untrust - hello_t.gsub(/./, a).untrusted?.should == true - hello_t.gsub(/./, empty).untrusted?.should == true + hello_t.gsub(/./, a).untrusted?.should == true + hello_t.gsub(/./, empty).untrusted?.should == true - hello.gsub(/./, a_t).untrusted?.should == true - hello.gsub(/./, empty_t).untrusted?.should == true - hello.gsub(//, empty_t).untrusted?.should == true + hello.gsub(/./, a_t).untrusted?.should == true + hello.gsub(/./, empty_t).untrusted?.should == true + hello.gsub(//, empty_t).untrusted?.should == true - hello.gsub(//.untrust, "foo").untrusted?.should == false + hello.gsub(//.untrust, "foo").untrusted?.should == false + end end it "tries to convert pattern to a string using to_str" do @@ -322,26 +326,27 @@ describe "String#gsub with pattern and Hash" do "hello".gsub(/(.+)/, 'hello' => repl ).should == repl end - it "untrusts the result if the original string is untrusted" do - str = "Ghana".untrust - str.gsub(/[Aa]na/, 'ana' => '').untrusted?.should be_true - end + ruby_version_is ''...'2.7' do + it "untrusts the result if the original string is untrusted" do + str = "Ghana".untrust + str.gsub(/[Aa]na/, 'ana' => '').untrusted?.should be_true + end - it "untrusts the result if a hash value is untrusted" do - str = "Ghana" - str.gsub(/a$/, 'a' => 'di'.untrust).untrusted?.should be_true - end + it "untrusts the result if a hash value is untrusted" do + str = "Ghana" + str.gsub(/a$/, 'a' => 'di'.untrust).untrusted?.should be_true + end - it "taints the result if the original string is tainted" do - str = "Ghana".taint - str.gsub(/[Aa]na/, 'ana' => '').tainted?.should be_true - end + it "taints the result if the original string is tainted" do + str = "Ghana".taint + str.gsub(/[Aa]na/, 'ana' => '').tainted?.should be_true + end - it "taints the result if a hash value is tainted" do - str = "Ghana" - str.gsub(/a$/, 'a' => 'di'.taint).tainted?.should be_true + it "taints the result if a hash value is tainted" do + str = "Ghana" + str.gsub(/a$/, 'a' => 'di'.taint).tainted?.should be_true + end end - end describe "String#gsub! with pattern and Hash" do @@ -411,26 +416,27 @@ describe "String#gsub! with pattern and Hash" do "hello".gsub!(/(.+)/, 'hello' => repl ).should == repl end - it "keeps untrusted state" do - str = "Ghana".untrust - str.gsub!(/[Aa]na/, 'ana' => '').untrusted?.should be_true - end + ruby_version_is ''...'2.7' do + it "keeps untrusted state" do + str = "Ghana".untrust + str.gsub!(/[Aa]na/, 'ana' => '').untrusted?.should be_true + end - it "untrusts self if a hash value is untrusted" do - str = "Ghana" - str.gsub!(/a$/, 'a' => 'di'.untrust).untrusted?.should be_true - end + it "untrusts self if a hash value is untrusted" do + str = "Ghana" + str.gsub!(/a$/, 'a' => 'di'.untrust).untrusted?.should be_true + end - it "keeps tainted state" do - str = "Ghana".taint - str.gsub!(/[Aa]na/, 'ana' => '').tainted?.should be_true - end + it "keeps tainted state" do + str = "Ghana".taint + str.gsub!(/[Aa]na/, 'ana' => '').tainted?.should be_true + end - it "taints self if a hash value is tainted" do - str = "Ghana" - str.gsub!(/a$/, 'a' => 'di'.taint).tainted?.should be_true + it "taints self if a hash value is tainted" do + str = "Ghana" + str.gsub!(/a$/, 'a' => 'di'.taint).tainted?.should be_true + end end - end describe "String#gsub with pattern and block" do @@ -504,24 +510,26 @@ describe "String#gsub with pattern and block" do "hello".gsub(/.+/) { obj }.should == "ok" end - it "untrusts the result if the original string or replacement is untrusted" do - hello = "hello" - hello_t = "hello" - a = "a" - a_t = "a" - empty = "" - empty_t = "" + ruby_version_is ''...'2.7' do + it "untrusts the result if the original string or replacement is untrusted" do + hello = "hello" + hello_t = "hello" + a = "a" + a_t = "a" + empty = "" + empty_t = "" - hello_t.untrust; a_t.untrust; empty_t.untrust + hello_t.untrust; a_t.untrust; empty_t.untrust - hello_t.gsub(/./) { a }.untrusted?.should == true - hello_t.gsub(/./) { empty }.untrusted?.should == true + hello_t.gsub(/./) { a }.untrusted?.should == true + hello_t.gsub(/./) { empty }.untrusted?.should == true - hello.gsub(/./) { a_t }.untrusted?.should == true - hello.gsub(/./) { empty_t }.untrusted?.should == true - hello.gsub(//) { empty_t }.untrusted?.should == true + hello.gsub(/./) { a_t }.untrusted?.should == true + hello.gsub(/./) { empty_t }.untrusted?.should == true + hello.gsub(//) { empty_t }.untrusted?.should == true - hello.gsub(//.untrust) { "foo" }.untrusted?.should == false + hello.gsub(//.untrust) { "foo" }.untrusted?.should == false + end end it "uses the compatible encoding if they are compatible" do @@ -583,16 +591,18 @@ describe "String#gsub! with pattern and replacement" do a.should == "*¿** **é*?*" end - it "taints self if replacement is tainted" do - a = "hello" - a.gsub!(/./.taint, "foo").tainted?.should == false - a.gsub!(/./, "foo".taint).tainted?.should == true - end + ruby_version_is ''...'2.7' do + it "taints self if replacement is tainted" do + a = "hello" + a.gsub!(/./.taint, "foo").tainted?.should == false + a.gsub!(/./, "foo".taint).tainted?.should == true + end - it "untrusts self if replacement is untrusted" do - a = "hello" - a.gsub!(/./.untrust, "foo").untrusted?.should == false - a.gsub!(/./, "foo".untrust).untrusted?.should == true + it "untrusts self if replacement is untrusted" do + a = "hello" + a.gsub!(/./.untrust, "foo").untrusted?.should == false + a.gsub!(/./, "foo".untrust).untrusted?.should == true + end end it "returns nil if no modifications were made" do @@ -620,16 +630,18 @@ describe "String#gsub! with pattern and block" do a.should == "h*ll*" end - it "taints self if block's result is tainted" do - a = "hello" - a.gsub!(/./.taint) { "foo" }.tainted?.should == false - a.gsub!(/./) { "foo".taint }.tainted?.should == true - end + ruby_version_is ''...'2.7' do + it "taints self if block's result is tainted" do + a = "hello" + a.gsub!(/./.taint) { "foo" }.tainted?.should == false + a.gsub!(/./) { "foo".taint }.tainted?.should == true + end - it "untrusts self if block's result is untrusted" do - a = "hello" - a.gsub!(/./.untrust) { "foo" }.untrusted?.should == false - a.gsub!(/./) { "foo".untrust }.untrusted?.should == true + it "untrusts self if block's result is untrusted" do + a = "hello" + a.gsub!(/./.untrust) { "foo" }.untrusted?.should == false + a.gsub!(/./) { "foo".untrust }.untrusted?.should == true + end end it "returns nil if no modifications were made" do diff --git a/spec/ruby/core/string/insert_spec.rb b/spec/ruby/core/string/insert_spec.rb index 588b8ab272..de7c12423a 100644 --- a/spec/ruby/core/string/insert_spec.rb +++ b/spec/ruby/core/string/insert_spec.rb @@ -41,14 +41,16 @@ describe "String#insert with index, other" do "abcd".insert(-3, other).should == "abXYZcd" end - it "taints self if string to insert is tainted" do - str = "abcd" - str.insert(0, "T".taint).tainted?.should == true - - str = "abcd" - other = mock('T') - def other.to_str() "T".taint end - str.insert(0, other).tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints self if string to insert is tainted" do + str = "abcd" + str.insert(0, "T".taint).tainted?.should == true + + str = "abcd" + other = mock('T') + def other.to_str() "T".taint end + str.insert(0, other).tainted?.should == true + end end it "raises a TypeError if other can't be converted to string" do diff --git a/spec/ruby/core/string/inspect_spec.rb b/spec/ruby/core/string/inspect_spec.rb index c1674c73c8..8ddbae132a 100644 --- a/spec/ruby/core/string/inspect_spec.rb +++ b/spec/ruby/core/string/inspect_spec.rb @@ -3,14 +3,16 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "String#inspect" do - it "taints the result if self is tainted" do - "foo".taint.inspect.tainted?.should == true - "foo\n".taint.inspect.tainted?.should == true - end + ruby_version_is ''...'2.7' do + it "taints the result if self is tainted" do + "foo".taint.inspect.tainted?.should == true + "foo\n".taint.inspect.tainted?.should == true + end - it "untrusts the result if self is untrusted" do - "foo".untrust.inspect.untrusted?.should == true - "foo\n".untrust.inspect.untrusted?.should == true + it "untrusts the result if self is untrusted" do + "foo".untrust.inspect.untrusted?.should == true + "foo\n".untrust.inspect.untrusted?.should == true + end end it "does not return a subclass instance" do diff --git a/spec/ruby/core/string/ljust_spec.rb b/spec/ruby/core/string/ljust_spec.rb index ed4cb86859..f377e39775 100644 --- a/spec/ruby/core/string/ljust_spec.rb +++ b/spec/ruby/core/string/ljust_spec.rb @@ -31,12 +31,14 @@ describe "String#ljust with length, padding" do "radiology".ljust(8, '-').should == "radiology" end - it "taints result when self or padstr is tainted" do - "x".taint.ljust(4).tainted?.should == true - "x".taint.ljust(0).tainted?.should == true - "".taint.ljust(0).tainted?.should == true - "x".taint.ljust(4, "*").tainted?.should == true - "x".ljust(4, "*".taint).tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints result when self or padstr is tainted" do + "x".taint.ljust(4).tainted?.should == true + "x".taint.ljust(0).tainted?.should == true + "".taint.ljust(0).tainted?.should == true + "x".taint.ljust(4, "*").tainted?.should == true + "x".ljust(4, "*".taint).tainted?.should == true + end end it "tries to convert length to an integer using to_int" do @@ -81,10 +83,12 @@ describe "String#ljust with length, padding" do "foo".ljust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) end - it "when padding is tainted and self is untainted returns a tainted string if and only if length is longer than self" do - "hello".ljust(4, 'X'.taint).tainted?.should be_false - "hello".ljust(5, 'X'.taint).tainted?.should be_false - "hello".ljust(6, 'X'.taint).tainted?.should be_true + ruby_version_is ''...'2.7' do + it "when padding is tainted and self is untainted returns a tainted string if and only if length is longer than self" do + "hello".ljust(4, 'X'.taint).tainted?.should be_false + "hello".ljust(5, 'X'.taint).tainted?.should be_false + "hello".ljust(6, 'X'.taint).tainted?.should be_true + end end describe "with width" do diff --git a/spec/ruby/core/string/lstrip_spec.rb b/spec/ruby/core/string/lstrip_spec.rb index 7f9363d398..b1a4e8541f 100644 --- a/spec/ruby/core/string/lstrip_spec.rb +++ b/spec/ruby/core/string/lstrip_spec.rb @@ -14,10 +14,12 @@ describe "String#lstrip" do "\x00hello".lstrip.should == "\x00hello" end - it "taints the result when self is tainted" do - "".taint.lstrip.tainted?.should == true - "ok".taint.lstrip.tainted?.should == true - " ok".taint.lstrip.tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints the result when self is tainted" do + "".taint.lstrip.tainted?.should == true + "ok".taint.lstrip.tainted?.should == true + " ok".taint.lstrip.tainted?.should == true + end end end diff --git a/spec/ruby/core/string/modulo_spec.rb b/spec/ruby/core/string/modulo_spec.rb index 0ac0963403..a16112bf44 100644 --- a/spec/ruby/core/string/modulo_spec.rb +++ b/spec/ruby/core/string/modulo_spec.rb @@ -297,24 +297,26 @@ describe "String#%" do end end - it "always taints the result when the format string is tainted" do - universal = mock('0') - def universal.to_int() 0 end - def universal.to_str() "0" end - def universal.to_f() 0.0 end - - [ - "", "foo", - "%b", "%B", "%c", "%d", "%e", "%E", - "%f", "%g", "%G", "%i", "%o", "%p", - "%s", "%u", "%x", "%X" - ].each do |format| - subcls_format = StringSpecs::MyString.new(format) - subcls_format.taint - format.taint - - (format % universal).tainted?.should == true - (subcls_format % universal).tainted?.should == true + ruby_version_is ''...'2.7' do + it "always taints the result when the format string is tainted" do + universal = mock('0') + def universal.to_int() 0 end + def universal.to_str() "0" end + def universal.to_f() 0.0 end + + [ + "", "foo", + "%b", "%B", "%c", "%d", "%e", "%E", + "%f", "%g", "%G", "%i", "%o", "%p", + "%s", "%u", "%x", "%X" + ].each do |format| + subcls_format = StringSpecs::MyString.new(format) + subcls_format.taint + format.taint + + (format % universal).tainted?.should == true + (subcls_format % universal).tainted?.should == true + end end end @@ -571,16 +573,18 @@ describe "String#%" do # ("%p" % obj).should == "obj" end - it "taints result for %p when argument.inspect is tainted" do - obj = mock('x') - def obj.inspect() "x".taint end + ruby_version_is ''...'2.7' do + it "taints result for %p when argument.inspect is tainted" do + obj = mock('x') + def obj.inspect() "x".taint end - ("%p" % obj).tainted?.should == true + ("%p" % obj).tainted?.should == true - obj = mock('x'); obj.taint - def obj.inspect() "x" end + obj = mock('x'); obj.taint + def obj.inspect() "x" end - ("%p" % obj).tainted?.should == false + ("%p" % obj).tainted?.should == false + end end it "supports string formats using %s" do @@ -611,9 +615,11 @@ describe "String#%" do # ("%s" % obj).should == "obj" end - it "taints result for %s when argument is tainted" do - ("%s" % "x".taint).tainted?.should == true - ("%s" % mock('x').taint).tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints result for %s when argument is tainted" do + ("%s" % "x".taint).tainted?.should == true + ("%s" % mock('x').taint).tainted?.should == true + end end # MRI crashes on this one. @@ -776,8 +782,10 @@ describe "String#%" do (format % "0xA").should == (format % 0xA) end - it "doesn't taint the result for #{format} when argument is tainted" do - (format % "5".taint).tainted?.should == false + ruby_version_is ''...'2.7' do + it "doesn't taint the result for #{format} when argument is tainted" do + (format % "5".taint).tainted?.should == false + end end end diff --git a/spec/ruby/core/string/plus_spec.rb b/spec/ruby/core/string/plus_spec.rb index b8e3bf0a4b..9f0db6427c 100644 --- a/spec/ruby/core/string/plus_spec.rb +++ b/spec/ruby/core/string/plus_spec.rb @@ -32,13 +32,15 @@ describe "String#+" do ("hello" + StringSpecs::MyString.new("")).should be_an_instance_of(String) end - it "taints the result when self or other is tainted" do - strs = ["", "OK", StringSpecs::MyString.new(""), StringSpecs::MyString.new("OK")] - strs += strs.map { |s| s.dup.taint } - - strs.each do |str| - strs.each do |other| - (str + other).tainted?.should == (str.tainted? | other.tainted?) + ruby_version_is ''...'2.7' do + it "taints the result when self or other is tainted" do + strs = ["", "OK", StringSpecs::MyString.new(""), StringSpecs::MyString.new("OK")] + strs += strs.map { |s| s.dup.taint } + + strs.each do |str| + strs.each do |other| + (str + other).tainted?.should == (str.tainted? | other.tainted?) + end end end end diff --git a/spec/ruby/core/string/prepend_spec.rb b/spec/ruby/core/string/prepend_spec.rb index 485c578e2d..c20c5a9e59 100644 --- a/spec/ruby/core/string/prepend_spec.rb +++ b/spec/ruby/core/string/prepend_spec.rb @@ -34,12 +34,14 @@ describe "String#prepend" do a.should == "hello world" end - it "taints self if other is tainted" do - x = "x" - x.prepend("".taint).tainted?.should be_true + ruby_version_is ''...'2.7' do + it "taints self if other is tainted" do + x = "x" + x.prepend("".taint).tainted?.should be_true - x = "x" - x.prepend("y".taint).tainted?.should be_true + x = "x" + x.prepend("y".taint).tainted?.should be_true + end end it "takes multiple arguments" do diff --git a/spec/ruby/core/string/reverse_spec.rb b/spec/ruby/core/string/reverse_spec.rb index 3941ea0521..eef46063a5 100644 --- a/spec/ruby/core/string/reverse_spec.rb +++ b/spec/ruby/core/string/reverse_spec.rb @@ -10,9 +10,11 @@ describe "String#reverse" do "".reverse.should == "" end - it "taints the result if self is tainted" do - "".taint.reverse.tainted?.should == true - "m".taint.reverse.tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints the result if self is tainted" do + "".taint.reverse.tainted?.should == true + "m".taint.reverse.tainted?.should == true + end end it "reverses a string with multi byte characters" do diff --git a/spec/ruby/core/string/rjust_spec.rb b/spec/ruby/core/string/rjust_spec.rb index 1ba298e8f3..9285ecb6a7 100644 --- a/spec/ruby/core/string/rjust_spec.rb +++ b/spec/ruby/core/string/rjust_spec.rb @@ -31,12 +31,14 @@ describe "String#rjust with length, padding" do "radiology".rjust(8, '-').should == "radiology" end - it "taints result when self or padstr is tainted" do - "x".taint.rjust(4).tainted?.should == true - "x".taint.rjust(0).tainted?.should == true - "".taint.rjust(0).tainted?.should == true - "x".taint.rjust(4, "*").tainted?.should == true - "x".rjust(4, "*".taint).tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints result when self or padstr is tainted" do + "x".taint.rjust(4).tainted?.should == true + "x".taint.rjust(0).tainted?.should == true + "".taint.rjust(0).tainted?.should == true + "x".taint.rjust(4, "*").tainted?.should == true + "x".rjust(4, "*".taint).tainted?.should == true + end end it "tries to convert length to an integer using to_int" do @@ -81,10 +83,12 @@ describe "String#rjust with length, padding" do "foo".rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) end - it "when padding is tainted and self is untainted returns a tainted string if and only if length is longer than self" do - "hello".rjust(4, 'X'.taint).tainted?.should be_false - "hello".rjust(5, 'X'.taint).tainted?.should be_false - "hello".rjust(6, 'X'.taint).tainted?.should be_true + ruby_version_is ''...'2.7' do + it "when padding is tainted and self is untainted returns a tainted string if and only if length is longer than self" do + "hello".rjust(4, 'X'.taint).tainted?.should be_false + "hello".rjust(5, 'X'.taint).tainted?.should be_false + "hello".rjust(6, 'X'.taint).tainted?.should be_true + end end describe "with width" do diff --git a/spec/ruby/core/string/rstrip_spec.rb b/spec/ruby/core/string/rstrip_spec.rb index 2f32836e54..9482765e89 100644 --- a/spec/ruby/core/string/rstrip_spec.rb +++ b/spec/ruby/core/string/rstrip_spec.rb @@ -14,10 +14,12 @@ describe "String#rstrip" do "\x00 \x00hello\x00 \x00".rstrip.should == "\x00 \x00hello" end - it "taints the result when self is tainted" do - "".taint.rstrip.tainted?.should == true - "ok".taint.rstrip.tainted?.should == true - "ok ".taint.rstrip.tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints the result when self is tainted" do + "".taint.rstrip.tainted?.should == true + "ok".taint.rstrip.tainted?.should == true + "ok ".taint.rstrip.tainted?.should == true + end end end diff --git a/spec/ruby/core/string/scan_spec.rb b/spec/ruby/core/string/scan_spec.rb index 06400fc745..024e97022a 100644 --- a/spec/ruby/core/string/scan_spec.rb +++ b/spec/ruby/core/string/scan_spec.rb @@ -65,24 +65,26 @@ describe "String#scan" do -> { "cruel world".scan(mock('x')) }.should raise_error(TypeError) end - it "taints the results if the String argument is tainted" do - a = "hello hello hello".scan("hello".taint) - a.each { |m| m.tainted?.should be_true } - end + ruby_version_is ''...'2.7' do + it "taints the results if the String argument is tainted" do + a = "hello hello hello".scan("hello".taint) + a.each { |m| m.tainted?.should be_true } + end - it "taints the results when passed a String argument if self is tainted" do - a = "hello hello hello".taint.scan("hello") - a.each { |m| m.tainted?.should be_true } - end + it "taints the results when passed a String argument if self is tainted" do + a = "hello hello hello".taint.scan("hello") + a.each { |m| m.tainted?.should be_true } + end - it "taints the results if the Regexp argument is tainted" do - a = "hello".scan(/./.taint) - a.each { |m| m.tainted?.should be_true } - end + it "taints the results if the Regexp argument is tainted" do + a = "hello".scan(/./.taint) + a.each { |m| m.tainted?.should be_true } + end - it "taints the results when passed a Regexp argument if self is tainted" do - a = "hello".taint.scan(/./) - a.each { |m| m.tainted?.should be_true } + it "taints the results when passed a Regexp argument if self is tainted" do + a = "hello".taint.scan(/./) + a.each { |m| m.tainted?.should be_true } + end end # jruby/jruby#5513 @@ -171,20 +173,22 @@ describe "String#scan with pattern and block" do $~.should == nil end - it "taints the results if the String argument is tainted" do - "hello hello hello".scan("hello".taint).each { |m| m.tainted?.should be_true } - end + ruby_version_is ''...'2.7' do + it "taints the results if the String argument is tainted" do + "hello hello hello".scan("hello".taint).each { |m| m.tainted?.should be_true } + end - it "taints the results when passed a String argument if self is tainted" do - "hello hello hello".taint.scan("hello").each { |m| m.tainted?.should be_true } - end + it "taints the results when passed a String argument if self is tainted" do + "hello hello hello".taint.scan("hello").each { |m| m.tainted?.should be_true } + end - it "taints the results if the Regexp argument is tainted" do - "hello".scan(/./.taint).each { |m| m.tainted?.should be_true } - end + it "taints the results if the Regexp argument is tainted" do + "hello".scan(/./.taint).each { |m| m.tainted?.should be_true } + end - it "taints the results when passed a Regexp argument if self is tainted" do - "hello".taint.scan(/./).each { |m| m.tainted?.should be_true } + it "taints the results when passed a Regexp argument if self is tainted" do + "hello".taint.scan(/./).each { |m| m.tainted?.should be_true } + end end it "passes block arguments as individual arguments when blocks are provided" do diff --git a/spec/ruby/core/string/shared/chars.rb b/spec/ruby/core/string/shared/chars.rb index c8716521bd..9c7a4deb8b 100644 --- a/spec/ruby/core/string/shared/chars.rb +++ b/spec/ruby/core/string/shared/chars.rb @@ -64,15 +64,17 @@ describe :string_chars, shared: true do ] end - it "taints resulting strings when self is tainted" do - str = "hello" + ruby_version_is ''...'2.7' do + it "taints resulting strings when self is tainted" do + str = "hello" - str.send(@method) do |x| - x.tainted?.should == false - end + str.send(@method) do |x| + x.tainted?.should == false + end - str.dup.taint.send(@method) do |x| - x.tainted?.should == true + str.dup.taint.send(@method) do |x| + x.tainted?.should == true + end end end end diff --git a/spec/ruby/core/string/shared/concat.rb b/spec/ruby/core/string/shared/concat.rb index 53a8bc23fb..435158496e 100644 --- a/spec/ruby/core/string/shared/concat.rb +++ b/spec/ruby/core/string/shared/concat.rb @@ -39,14 +39,16 @@ describe :string_concat, shared: true do str.should be_an_instance_of(StringSpecs::MyString) end - it "taints self if other is tainted" do - "x".send(@method, "".taint).tainted?.should == true - "x".send(@method, "y".taint).tainted?.should == true - end + ruby_version_is ''...'2.7' do + it "taints self if other is tainted" do + "x".send(@method, "".taint).tainted?.should == true + "x".send(@method, "y".taint).tainted?.should == true + end - it "untrusts self if other is untrusted" do - "x".send(@method, "".untrust).untrusted?.should == true - "x".send(@method, "y".untrust).untrusted?.should == true + it "untrusts self if other is untrusted" do + "x".send(@method, "".untrust).untrusted?.should == true + "x".send(@method, "y".untrust).untrusted?.should == true + end end describe "with Integer" do diff --git a/spec/ruby/core/string/shared/each_line.rb b/spec/ruby/core/string/shared/each_line.rb index 241a90eee3..843b123f57 100644 --- a/spec/ruby/core/string/shared/each_line.rb +++ b/spec/ruby/core/string/shared/each_line.rb @@ -40,10 +40,12 @@ describe :string_each_line, shared: true do b.should == ["foo\n", "🤡🤡🤡🤡🤡🤡🤡\n", "bar\n", "baz\n"] end - it "taints substrings that are passed to the block if self is tainted" do - "one\ntwo\r\nthree".taint.send(@method) { |s| s.tainted?.should == true } + ruby_version_is ''...'2.7' do + it "taints substrings that are passed to the block if self is tainted" do + "one\ntwo\r\nthree".taint.send(@method) { |s| s.tainted?.should == true } - "x.y.".send(@method, ".".taint) { |s| s.tainted?.should == false } + "x.y.".send(@method, ".".taint) { |s| s.tainted?.should == false } + end end it "passes self as a whole to the block if the separator is nil" do diff --git a/spec/ruby/core/string/shared/replace.rb b/spec/ruby/core/string/shared/replace.rb index f13afb3f95..620021eb92 100644 --- a/spec/ruby/core/string/shared/replace.rb +++ b/spec/ruby/core/string/shared/replace.rb @@ -10,32 +10,34 @@ describe :string_replace, shared: true do a.should == "another string" end - it "taints self if other is tainted" do - a = "" - b = "".taint - a.send(@method, b) - a.tainted?.should == true - end + ruby_version_is ''...'2.7' do + it "taints self if other is tainted" do + a = "" + b = "".taint + a.send(@method, b) + a.tainted?.should == true + end - it "does not untaint self if other is untainted" do - a = "".taint - b = "" - a.send(@method, b) - a.tainted?.should == true - end + it "does not untaint self if other is untainted" do + a = "".taint + b = "" + a.send(@method, b) + a.tainted?.should == true + end - it "untrusts self if other is untrusted" do - a = "" - b = "".untrust - a.send(@method, b) - a.untrusted?.should == true - end + it "untrusts self if other is untrusted" do + a = "" + b = "".untrust + a.send(@method, b) + a.untrusted?.should == true + end - it "does not trust self if other is trusted" do - a = "".untrust - b = "" - a.send(@method, b) - a.untrusted?.should == true + it "does not trust self if other is trusted" do + a = "".untrust + b = "" + a.send(@method, b) + a.untrusted?.should == true + end end it "replaces the encoding of self with that of other" do diff --git a/spec/ruby/core/string/shared/slice.rb b/spec/ruby/core/string/shared/slice.rb index ef7a8787ce..b192005369 100644 --- a/spec/ruby/core/string/shared/slice.rb +++ b/spec/ruby/core/string/shared/slice.rb @@ -80,13 +80,15 @@ describe :string_slice_index_length, shared: true do "hello there".send(@method, -3,2).should == "er" end - it "always taints resulting strings when self is tainted" do - str = "hello world" - str.taint - - str.send(@method, 0,0).tainted?.should == true - str.send(@method, 0,1).tainted?.should == true - str.send(@method, 2,1).tainted?.should == true + ruby_version_is ''...'2.7' do + it "always taints resulting strings when self is tainted" do + str = "hello world" + str.taint + + str.send(@method, 0,0).tainted?.should == true + str.send(@method, 0,1).tainted?.should == true + str.send(@method, 2,1).tainted?.should == true + end end it "returns a string with the same encoding" do @@ -234,16 +236,18 @@ describe :string_slice_range, shared: true do "x".send(@method, 1...-1).should == "" end - it "always taints resulting strings when self is tainted" do - str = "hello world" - str.taint + ruby_version_is ''...'2.7' do + it "always taints resulting strings when self is tainted" do + str = "hello world" + str.taint - str.send(@method, 0..0).tainted?.should == true - str.send(@method, 0...0).tainted?.should == true - str.send(@method, 0..1).tainted?.should == true - str.send(@method, 0...1).tainted?.should == true - str.send(@method, 2..3).tainted?.should == true - str.send(@method, 2..0).tainted?.should == true + str.send(@method, 0..0).tainted?.should == true + str.send(@method, 0...0).tainted?.should == true + str.send(@method, 0..1).tainted?.should == true + str.send(@method, 0...1).tainted?.should == true + str.send(@method, 2..3).tainted?.should == true + str.send(@method, 2..0).tainted?.should == true + end end it "returns subclass instances" do @@ -302,23 +306,25 @@ describe :string_slice_regexp, shared: true do end not_supported_on :opal do - it "always taints resulting strings when self or regexp is tainted" do - strs = ["hello world"] - strs += strs.map { |s| s.dup.taint } + ruby_version_is ''...'2.7' do + it "always taints resulting strings when self or regexp is tainted" do + strs = ["hello world"] + strs += strs.map { |s| s.dup.taint } - strs.each do |str| - str.send(@method, //).tainted?.should == str.tainted? - str.send(@method, /hello/).tainted?.should == str.tainted? + strs.each do |str| + str.send(@method, //).tainted?.should == str.tainted? + str.send(@method, /hello/).tainted?.should == str.tainted? - tainted_re = /./ - tainted_re.taint + tainted_re = /./ + tainted_re.taint - str.send(@method, tainted_re).tainted?.should == true + str.send(@method, tainted_re).tainted?.should == true + end end - end - it "returns an untrusted string if the regexp is untrusted" do - "hello".send(@method, /./.untrust).untrusted?.should be_true + it "returns an untrusted string if the regexp is untrusted" do + "hello".send(@method, /./.untrust).untrusted?.should be_true + end end end @@ -352,31 +358,33 @@ describe :string_slice_regexp_index, shared: true do "har".send(@method, /(.)(.)(.)/, -3).should == "h" end - it "always taints resulting strings when self or regexp is tainted" do - strs = ["hello world"] - strs += strs.map { |s| s.dup.taint } + ruby_version_is ''...'2.7' do + it "always taints resulting strings when self or regexp is tainted" do + strs = ["hello world"] + strs += strs.map { |s| s.dup.taint } - strs.each do |str| - str.send(@method, //, 0).tainted?.should == str.tainted? - str.send(@method, /hello/, 0).tainted?.should == str.tainted? + strs.each do |str| + str.send(@method, //, 0).tainted?.should == str.tainted? + str.send(@method, /hello/, 0).tainted?.should == str.tainted? - str.send(@method, /(.)(.)(.)/, 0).tainted?.should == str.tainted? - str.send(@method, /(.)(.)(.)/, 1).tainted?.should == str.tainted? - str.send(@method, /(.)(.)(.)/, -1).tainted?.should == str.tainted? - str.send(@method, /(.)(.)(.)/, -2).tainted?.should == str.tainted? + str.send(@method, /(.)(.)(.)/, 0).tainted?.should == str.tainted? + str.send(@method, /(.)(.)(.)/, 1).tainted?.should == str.tainted? + str.send(@method, /(.)(.)(.)/, -1).tainted?.should == str.tainted? + str.send(@method, /(.)(.)(.)/, -2).tainted?.should == str.tainted? - tainted_re = /(.)(.)(.)/ - tainted_re.taint + tainted_re = /(.)(.)(.)/ + tainted_re.taint - str.send(@method, tainted_re, 0).tainted?.should == true - str.send(@method, tainted_re, 1).tainted?.should == true - str.send(@method, tainted_re, -1).tainted?.should == true + str.send(@method, tainted_re, 0).tainted?.should == true + str.send(@method, tainted_re, 1).tainted?.should == true + str.send(@method, tainted_re, -1).tainted?.should == true + end end - end - not_supported_on :opal do - it "returns an untrusted string if the regexp is untrusted" do - "hello".send(@method, /(.)/.untrust, 1).untrusted?.should be_true + not_supported_on :opal do + it "returns an untrusted string if the regexp is untrusted" do + "hello".send(@method, /(.)/.untrust, 1).untrusted?.should be_true + end end end @@ -432,15 +440,17 @@ describe :string_slice_string, shared: true do "hello there".send(@method, s).should == s end - it "taints resulting strings when other is tainted" do - strs = ["", "hello world", "hello"] - strs += strs.map { |s| s.dup.taint } + ruby_version_is ''...'2.7' do + it "taints resulting strings when other is tainted" do + strs = ["", "hello world", "hello"] + strs += strs.map { |s| s.dup.taint } - strs.each do |str| - strs.each do |other| - r = str.send(@method, other) + strs.each do |str| + strs.each do |other| + r = str.send(@method, other) - r.tainted?.should == !r.nil? & other.tainted? + r.tainted?.should == !r.nil? & other.tainted? + end end end end @@ -493,25 +503,27 @@ describe :string_slice_regexp_group, shared: true do "hello there".send(@method, /(?<g>h(?<g>.))/, 'g').should == "e" end - it "always taints resulting strings when self or regexp is tainted" do - strs = ["hello world"] - strs += strs.map { |s| s.dup.taint } + ruby_version_is ''...'2.7' do + it "always taints resulting strings when self or regexp is tainted" do + strs = ["hello world"] + strs += strs.map { |s| s.dup.taint } - strs.each do |str| - str.send(@method, /(?<hi>hello)/, 'hi').tainted?.should == str.tainted? + strs.each do |str| + str.send(@method, /(?<hi>hello)/, 'hi').tainted?.should == str.tainted? - str.send(@method, /(?<g>(.)(.)(.))/, 'g').tainted?.should == str.tainted? - str.send(@method, /(?<h>.)(.)(.)/, 'h').tainted?.should == str.tainted? - str.send(@method, /(.)(?<a>.)(.)/, 'a').tainted?.should == str.tainted? - str.send(@method, /(.)(.)(?<r>.)/, 'r').tainted?.should == str.tainted? - str.send(@method, /(?<h>.)(?<a>.)(?<r>.)/, 'r').tainted?.should == str.tainted? + str.send(@method, /(?<g>(.)(.)(.))/, 'g').tainted?.should == str.tainted? + str.send(@method, /(?<h>.)(.)(.)/, 'h').tainted?.should == str.tainted? + str.send(@method, /(.)(?<a>.)(.)/, 'a').tainted?.should == str.tainted? + str.send(@method, /(.)(.)(?<r>.)/, 'r').tainted?.should == str.tainted? + str.send(@method, /(?<h>.)(?<a>.)(?<r>.)/, 'r').tainted?.should == str.tainted? - tainted_re = /(?<a>.)(?<b>.)(?<c>.)/ - tainted_re.taint + tainted_re = /(?<a>.)(?<b>.)(?<c>.)/ + tainted_re.taint - str.send(@method, tainted_re, 'a').tainted?.should be_true - str.send(@method, tainted_re, 'b').tainted?.should be_true - str.send(@method, tainted_re, 'c').tainted?.should be_true + str.send(@method, tainted_re, 'a').tainted?.should be_true + str.send(@method, tainted_re, 'b').tainted?.should be_true + str.send(@method, tainted_re, 'c').tainted?.should be_true + end end end diff --git a/spec/ruby/core/string/shared/succ.rb b/spec/ruby/core/string/shared/succ.rb index 31b4a8b5dd..80e4659102 100644 --- a/spec/ruby/core/string/shared/succ.rb +++ b/spec/ruby/core/string/shared/succ.rb @@ -65,9 +65,11 @@ describe :string_succ, shared: true do StringSpecs::MyString.new("z").send(@method).should be_an_instance_of(StringSpecs::MyString) end - it "taints the result if self is tainted" do - ["", "a", "z", "Z", "9", "\xFF", "\xFF\xFF"].each do |s| - s.taint.send(@method).tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints the result if self is tainted" do + ["", "a", "z", "Z", "9", "\xFF", "\xFF\xFF"].each do |s| + s.taint.send(@method).tainted?.should == true + end end end end diff --git a/spec/ruby/core/string/shared/to_s.rb b/spec/ruby/core/string/shared/to_s.rb index a5a13e4f26..36283be4d0 100644 --- a/spec/ruby/core/string/shared/to_s.rb +++ b/spec/ruby/core/string/shared/to_s.rb @@ -11,8 +11,10 @@ describe :string_to_s, shared: true do s.should be_an_instance_of(String) end - it "taints the result when self is tainted" do - "x".taint.send(@method).tainted?.should == true - StringSpecs::MyString.new("x").taint.send(@method).tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints the result when self is tainted" do + "x".taint.send(@method).tainted?.should == true + StringSpecs::MyString.new("x").taint.send(@method).tainted?.should == true + end end end diff --git a/spec/ruby/core/string/slice_spec.rb b/spec/ruby/core/string/slice_spec.rb index 2af663117c..f9f4938af3 100644 --- a/spec/ruby/core/string/slice_spec.rb +++ b/spec/ruby/core/string/slice_spec.rb @@ -94,12 +94,14 @@ describe "String#slice! with index, length" do a.should == "h" end - it "always taints resulting strings when self is tainted" do - str = "hello world" - str.taint + ruby_version_is ''...'2.7' do + it "always taints resulting strings when self is tainted" do + str = "hello world" + str.taint - str.slice!(0, 0).tainted?.should == true - str.slice!(2, 1).tainted?.should == true + str.slice!(0, 0).tainted?.should == true + str.slice!(2, 1).tainted?.should == true + end end it "returns nil if the given position is out of self" do @@ -184,12 +186,14 @@ describe "String#slice! Range" do b.should == "hello" end - it "always taints resulting strings when self is tainted" do - str = "hello world" - str.taint + ruby_version_is ''...'2.7' do + it "always taints resulting strings when self is tainted" do + str = "hello world" + str.taint - str.slice!(0..0).tainted?.should == true - str.slice!(2..3).tainted?.should == true + str.slice!(0..0).tainted?.should == true + str.slice!(2..3).tainted?.should == true + end end it "returns subclass instances" do @@ -271,26 +275,28 @@ describe "String#slice! with Regexp" do s.should == "this is a string" end - it "always taints resulting strings when self or regexp is tainted" do - strs = ["hello world"] - strs += strs.map { |s| s.dup.taint } + ruby_version_is ''...'2.7' do + it "always taints resulting strings when self or regexp is tainted" do + strs = ["hello world"] + strs += strs.map { |s| s.dup.taint } - strs.each do |str| - str = str.dup - str.slice!(//).tainted?.should == str.tainted? - str.slice!(/hello/).tainted?.should == str.tainted? + strs.each do |str| + str = str.dup + str.slice!(//).tainted?.should == str.tainted? + str.slice!(/hello/).tainted?.should == str.tainted? - tainted_re = /./ - tainted_re.taint + tainted_re = /./ + tainted_re.taint - str.slice!(tainted_re).tainted?.should == true + str.slice!(tainted_re).tainted?.should == true + end end - end - it "doesn't taint self when regexp is tainted" do - s = "hello" - s.slice!(/./.taint) - s.tainted?.should == false + it "doesn't taint self when regexp is tainted" do + s = "hello" + s.slice!(/./.taint) + s.tainted?.should == false + end end it "returns subclass instances" do @@ -330,26 +336,28 @@ describe "String#slice! with Regexp, index" do str.should == "ho here" end - it "always taints resulting strings when self or regexp is tainted" do - strs = ["hello world"] - strs += strs.map { |s| s.dup.taint } + ruby_version_is ''...'2.7' do + it "always taints resulting strings when self or regexp is tainted" do + strs = ["hello world"] + strs += strs.map { |s| s.dup.taint } - strs.each do |str| - str = str.dup - str.slice!(//, 0).tainted?.should == str.tainted? - str.slice!(/hello/, 0).tainted?.should == str.tainted? + strs.each do |str| + str = str.dup + str.slice!(//, 0).tainted?.should == str.tainted? + str.slice!(/hello/, 0).tainted?.should == str.tainted? - tainted_re = /(.)(.)(.)/ - tainted_re.taint + tainted_re = /(.)(.)(.)/ + tainted_re.taint - str.slice!(tainted_re, 1).tainted?.should == true + str.slice!(tainted_re, 1).tainted?.should == true + end end - end - it "doesn't taint self when regexp is tainted" do - s = "hello" - s.slice!(/(.)(.)/.taint, 1) - s.tainted?.should == false + it "doesn't taint self when regexp is tainted" do + s = "hello" + s.slice!(/(.)(.)/.taint, 1) + s.tainted?.should == false + end end it "returns nil if there was no match" do @@ -416,17 +424,19 @@ describe "String#slice! with String" do c.should == "he hello" end - it "taints resulting strings when other is tainted" do - strs = ["", "hello world", "hello"] - strs += strs.map { |s| s.dup.taint } + ruby_version_is ''...'2.7' do + it "taints resulting strings when other is tainted" do + strs = ["", "hello world", "hello"] + strs += strs.map { |s| s.dup.taint } - strs.each do |str| - str = str.dup - strs.each do |other| - other = other.dup - r = str.slice!(other) + strs.each do |str| + str = str.dup + strs.each do |other| + other = other.dup + r = str.slice!(other) - r.tainted?.should == !r.nil? & other.tainted? + r.tainted?.should == !r.nil? & other.tainted? + end end end end diff --git a/spec/ruby/core/string/split_spec.rb b/spec/ruby/core/string/split_spec.rb index 655f0dae76..cfb030ad8d 100644 --- a/spec/ruby/core/string/split_spec.rb +++ b/spec/ruby/core/string/split_spec.rb @@ -165,16 +165,18 @@ describe "String#split with String" do s.split(':').first.should == 'silly' end - it "taints the resulting strings if self is tainted" do - ["", "x.y.z.", " x y "].each do |str| - ["", ".", " "].each do |pat| - [-1, 0, 1, 2].each do |limit| - str.dup.taint.split(pat).each do |x| - x.tainted?.should == true - end - - str.split(pat.dup.taint).each do |x| - x.tainted?.should == false + ruby_version_is ''...'2.7' do + it "taints the resulting strings if self is tainted" do + ["", "x.y.z.", " x y "].each do |str| + ["", ".", " "].each do |pat| + [-1, 0, 1, 2].each do |limit| + str.dup.taint.split(pat).each do |x| + x.tainted?.should == true + end + + str.split(pat.dup.taint).each do |x| + x.tainted?.should == false + end end end end @@ -355,29 +357,31 @@ describe "String#split with Regexp" do s.split(/:/).first.should == 'silly' end - it "taints the resulting strings if self is tainted" do - ["", "x:y:z:", " x y "].each do |str| - [//, /:/, /\s+/].each do |pat| - [-1, 0, 1, 2].each do |limit| - str.dup.taint.split(pat, limit).each do |x| - # See the spec below for why the conditional is here - x.tainted?.should be_true unless x.empty? + ruby_version_is ''...'2.7' do + it "taints the resulting strings if self is tainted" do + ["", "x:y:z:", " x y "].each do |str| + [//, /:/, /\s+/].each do |pat| + [-1, 0, 1, 2].each do |limit| + str.dup.taint.split(pat, limit).each do |x| + # See the spec below for why the conditional is here + x.tainted?.should be_true unless x.empty? + end end end end end - end - it "taints an empty string if self is tainted" do - ":".taint.split(//, -1).last.tainted?.should be_true - end + it "taints an empty string if self is tainted" do + ":".taint.split(//, -1).last.tainted?.should be_true + end - it "doesn't taints the resulting strings if the Regexp is tainted" do - ["", "x:y:z:", " x y "].each do |str| - [//, /:/, /\s+/].each do |pat| - [-1, 0, 1, 2].each do |limit| - str.split(pat.dup.taint, limit).each do |x| - x.tainted?.should be_false + it "doesn't taints the resulting strings if the Regexp is tainted" do + ["", "x:y:z:", " x y "].each do |str| + [//, /:/, /\s+/].each do |pat| + [-1, 0, 1, 2].each do |limit| + str.split(pat.dup.taint, limit).each do |x| + x.tainted?.should be_false + end end end end diff --git a/spec/ruby/core/string/squeeze_spec.rb b/spec/ruby/core/string/squeeze_spec.rb index bcc320bb5b..2e96684b9d 100644 --- a/spec/ruby/core/string/squeeze_spec.rb +++ b/spec/ruby/core/string/squeeze_spec.rb @@ -54,12 +54,14 @@ describe "String#squeeze" do -> { s.squeeze("^e-b") }.should raise_error(ArgumentError) end - it "taints the result when self is tainted" do - "hello".taint.squeeze("e").tainted?.should == true - "hello".taint.squeeze("a-z").tainted?.should == true - - "hello".squeeze("e".taint).tainted?.should == false - "hello".squeeze("l".taint).tainted?.should == false + ruby_version_is ''...'2.7' do + it "taints the result when self is tainted" do + "hello".taint.squeeze("e").tainted?.should == true + "hello".taint.squeeze("a-z").tainted?.should == true + + "hello".squeeze("e".taint).tainted?.should == false + "hello".squeeze("l".taint).tainted?.should == false + end end it "tries to convert each set arg to a string using to_str" do diff --git a/spec/ruby/core/string/strip_spec.rb b/spec/ruby/core/string/strip_spec.rb index c205746483..728b3104fa 100644 --- a/spec/ruby/core/string/strip_spec.rb +++ b/spec/ruby/core/string/strip_spec.rb @@ -13,10 +13,12 @@ describe "String#strip" do " \x00 goodbye \x00 ".strip.should == "\x00 goodbye" end - it "taints the result when self is tainted" do - "".taint.strip.tainted?.should == true - "ok".taint.strip.tainted?.should == true - " ok ".taint.strip.tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints the result when self is tainted" do + "".taint.strip.tainted?.should == true + "ok".taint.strip.tainted?.should == true + " ok ".taint.strip.tainted?.should == true + end end end diff --git a/spec/ruby/core/string/sub_spec.rb b/spec/ruby/core/string/sub_spec.rb index 630f0d6b70..2a859c2fc7 100644 --- a/spec/ruby/core/string/sub_spec.rb +++ b/spec/ruby/core/string/sub_spec.rb @@ -137,24 +137,26 @@ describe "String#sub with pattern, replacement" do "hello".sub(/./, 'hah\\').should == 'hah\\ello' end - it "taints the result if the original string or replacement is tainted" do - hello = "hello" - hello_t = "hello" - a = "a" - a_t = "a" - empty = "" - empty_t = "" + ruby_version_is ''...'2.7' do + it "taints the result if the original string or replacement is tainted" do + hello = "hello" + hello_t = "hello" + a = "a" + a_t = "a" + empty = "" + empty_t = "" - hello_t.taint; a_t.taint; empty_t.taint + hello_t.taint; a_t.taint; empty_t.taint - hello_t.sub(/./, a).tainted?.should == true - hello_t.sub(/./, empty).tainted?.should == true + hello_t.sub(/./, a).tainted?.should == true + hello_t.sub(/./, empty).tainted?.should == true - hello.sub(/./, a_t).tainted?.should == true - hello.sub(/./, empty_t).tainted?.should == true - hello.sub(//, empty_t).tainted?.should == true + hello.sub(/./, a_t).tainted?.should == true + hello.sub(/./, empty_t).tainted?.should == true + hello.sub(//, empty_t).tainted?.should == true - hello.sub(//.taint, "foo").tainted?.should == false + hello.sub(//.taint, "foo").tainted?.should == false + end end it "tries to convert pattern to a string using to_str" do @@ -285,24 +287,26 @@ describe "String#sub with pattern and block" do "hello".sub(/.+/) { obj }.should == "ok" end - it "taints the result if the original string or replacement is tainted" do - hello = "hello" - hello_t = "hello" - a = "a" - a_t = "a" - empty = "" - empty_t = "" + ruby_version_is ''...'2.7' do + it "taints the result if the original string or replacement is tainted" do + hello = "hello" + hello_t = "hello" + a = "a" + a_t = "a" + empty = "" + empty_t = "" - hello_t.taint; a_t.taint; empty_t.taint + hello_t.taint; a_t.taint; empty_t.taint - hello_t.sub(/./) { a }.tainted?.should == true - hello_t.sub(/./) { empty }.tainted?.should == true + hello_t.sub(/./) { a }.tainted?.should == true + hello_t.sub(/./) { empty }.tainted?.should == true - hello.sub(/./) { a_t }.tainted?.should == true - hello.sub(/./) { empty_t }.tainted?.should == true - hello.sub(//) { empty_t }.tainted?.should == true + hello.sub(/./) { a_t }.tainted?.should == true + hello.sub(/./) { empty_t }.tainted?.should == true + hello.sub(//) { empty_t }.tainted?.should == true - hello.sub(//.taint) { "foo" }.tainted?.should == false + hello.sub(//.taint) { "foo" }.tainted?.should == false + end end end @@ -313,10 +317,12 @@ describe "String#sub! with pattern, replacement" do a.should == "h*llo" end - it "taints self if replacement is tainted" do - a = "hello" - a.sub!(/./.taint, "foo").tainted?.should == false - a.sub!(/./, "foo".taint).tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints self if replacement is tainted" do + a = "hello" + a.sub!(/./.taint, "foo").tainted?.should == false + a.sub!(/./, "foo".taint).tainted?.should == true + end end it "returns nil if no modifications were made" do @@ -361,10 +367,12 @@ describe "String#sub! with pattern and block" do offsets.should == [[1, 2]] end - it "taints self if block's result is tainted" do - a = "hello" - a.sub!(/./.taint) { "foo" }.tainted?.should == false - a.sub!(/./) { "foo".taint }.tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints self if block's result is tainted" do + a = "hello" + a.sub!(/./.taint) { "foo" }.tainted?.should == false + a.sub!(/./) { "foo".taint }.tainted?.should == true + end end it "returns nil if no modifications were made" do @@ -452,24 +460,26 @@ describe "String#sub with pattern and Hash" do "hello".sub(/(.+)/, 'hello' => repl ).should == repl end - it "untrusts the result if the original string is untrusted" do - str = "Ghana".untrust - str.sub(/[Aa]na/, 'ana' => '').untrusted?.should be_true - end + ruby_version_is ''...'2.7' do + it "untrusts the result if the original string is untrusted" do + str = "Ghana".untrust + str.sub(/[Aa]na/, 'ana' => '').untrusted?.should be_true + end - it "untrusts the result if a hash value is untrusted" do - str = "Ghana" - str.sub(/a$/, 'a' => 'di'.untrust).untrusted?.should be_true - end + it "untrusts the result if a hash value is untrusted" do + str = "Ghana" + str.sub(/a$/, 'a' => 'di'.untrust).untrusted?.should be_true + end - it "taints the result if the original string is tainted" do - str = "Ghana".taint - str.sub(/[Aa]na/, 'ana' => '').tainted?.should be_true - end + it "taints the result if the original string is tainted" do + str = "Ghana".taint + str.sub(/[Aa]na/, 'ana' => '').tainted?.should be_true + end - it "taints the result if a hash value is tainted" do - str = "Ghana" - str.sub(/a$/, 'a' => 'di'.taint).tainted?.should be_true + it "taints the result if a hash value is tainted" do + str = "Ghana" + str.sub(/a$/, 'a' => 'di'.taint).tainted?.should be_true + end end end @@ -537,24 +547,26 @@ describe "String#sub! with pattern and Hash" do "hello".sub!(/(.+)/, 'hello' => repl ).should == repl end - it "keeps untrusted state" do - str = "Ghana".untrust - str.sub!(/[Aa]na/, 'ana' => '').untrusted?.should be_true - end + ruby_version_is ''...'2.7' do + it "keeps untrusted state" do + str = "Ghana".untrust + str.sub!(/[Aa]na/, 'ana' => '').untrusted?.should be_true + end - it "untrusts self if a hash value is untrusted" do - str = "Ghana" - str.sub!(/a$/, 'a' => 'di'.untrust).untrusted?.should be_true - end + it "untrusts self if a hash value is untrusted" do + str = "Ghana" + str.sub!(/a$/, 'a' => 'di'.untrust).untrusted?.should be_true + end - it "keeps tainted state" do - str = "Ghana".taint - str.sub!(/[Aa]na/, 'ana' => '').tainted?.should be_true - end + it "keeps tainted state" do + str = "Ghana".taint + str.sub!(/[Aa]na/, 'ana' => '').tainted?.should be_true + end - it "taints self if a hash value is tainted" do - str = "Ghana" - str.sub!(/a$/, 'a' => 'di'.taint).tainted?.should be_true + it "taints self if a hash value is tainted" do + str = "Ghana" + str.sub!(/a$/, 'a' => 'di'.taint).tainted?.should be_true + end end end diff --git a/spec/ruby/core/string/swapcase_spec.rb b/spec/ruby/core/string/swapcase_spec.rb index 95edcec7d1..c1a1608a81 100644 --- a/spec/ruby/core/string/swapcase_spec.rb +++ b/spec/ruby/core/string/swapcase_spec.rb @@ -9,9 +9,11 @@ describe "String#swapcase" do "+++---111222???".swapcase.should == "+++---111222???" end - it "taints resulting string when self is tainted" do - "".taint.swapcase.tainted?.should == true - "hello".taint.swapcase.tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints resulting string when self is tainted" do + "".taint.swapcase.tainted?.should == true + "hello".taint.swapcase.tainted?.should == true + end end describe "full Unicode case mapping" do diff --git a/spec/ruby/core/string/tr_s_spec.rb b/spec/ruby/core/string/tr_s_spec.rb index 4380f2d548..a05e421e99 100644 --- a/spec/ruby/core/string/tr_s_spec.rb +++ b/spec/ruby/core/string/tr_s_spec.rb @@ -49,14 +49,16 @@ describe "String#tr_s" do StringSpecs::MyString.new("hello").tr_s("e", "a").should be_an_instance_of(StringSpecs::MyString) end - it "taints the result when self is tainted" do - ["h", "hello"].each do |str| - tainted_str = str.dup.taint + ruby_version_is ''...'2.7' do + it "taints the result when self is tainted" do + ["h", "hello"].each do |str| + tainted_str = str.dup.taint - tainted_str.tr_s("e", "a").tainted?.should == true + tainted_str.tr_s("e", "a").tainted?.should == true - str.tr_s("e".taint, "a").tainted?.should == false - str.tr_s("e", "a".taint).tainted?.should == false + str.tr_s("e".taint, "a").tainted?.should == false + str.tr_s("e", "a".taint).tainted?.should == false + end end end diff --git a/spec/ruby/core/string/tr_spec.rb b/spec/ruby/core/string/tr_spec.rb index 721ebab51c..ae826fd79b 100644 --- a/spec/ruby/core/string/tr_spec.rb +++ b/spec/ruby/core/string/tr_spec.rb @@ -61,14 +61,16 @@ describe "String#tr" do StringSpecs::MyString.new("hello").tr("e", "a").should be_an_instance_of(StringSpecs::MyString) end - it "taints the result when self is tainted" do - ["h", "hello"].each do |str| - tainted_str = str.dup.taint + ruby_version_is ''...'2.7' do + it "taints the result when self is tainted" do + ["h", "hello"].each do |str| + tainted_str = str.dup.taint - tainted_str.tr("e", "a").tainted?.should == true + tainted_str.tr("e", "a").tainted?.should == true - str.tr("e".taint, "a").tainted?.should == false - str.tr("e", "a".taint).tainted?.should == false + str.tr("e".taint, "a").tainted?.should == false + str.tr("e", "a".taint).tainted?.should == false + end end end diff --git a/spec/ruby/core/string/undump_spec.rb b/spec/ruby/core/string/undump_spec.rb index 315d27cad4..e83c53ce89 100644 --- a/spec/ruby/core/string/undump_spec.rb +++ b/spec/ruby/core/string/undump_spec.rb @@ -4,12 +4,14 @@ require_relative 'fixtures/classes' ruby_version_is '2.5' do describe "String#undump" do - it "taints the result if self is tainted" do - '"foo"'.taint.undump.tainted?.should == true - end + ruby_version_is ''...'2.7' do + it "taints the result if self is tainted" do + '"foo"'.taint.undump.tainted?.should == true + end - it "untrusts the result if self is untrusted" do - '"foo"'.untrust.undump.untrusted?.should == true + it "untrusts the result if self is untrusted" do + '"foo"'.untrust.undump.untrusted?.should == true + end end it "does not take into account if a string is frozen" do diff --git a/spec/ruby/core/string/unpack/p_spec.rb b/spec/ruby/core/string/unpack/p_spec.rb index a544bc29c1..3e187d674f 100644 --- a/spec/ruby/core/string/unpack/p_spec.rb +++ b/spec/ruby/core/string/unpack/p_spec.rb @@ -18,8 +18,10 @@ describe "String#unpack with format 'P'" do -> { packed.to_sym.to_s.unpack("P5") }.should raise_error(ArgumentError, /no associated pointer/) end - it "taints the unpacked string" do - ["hello"].pack("P").unpack("P5").first.tainted?.should be_true + ruby_version_is ''...'2.7' do + it "taints the unpacked string" do + ["hello"].pack("P").unpack("P5").first.tainted?.should be_true + end end it "reads as many characters as specified" do @@ -46,7 +48,9 @@ describe "String#unpack with format 'p'" do -> { packed.to_sym.to_s.unpack("p") }.should raise_error(ArgumentError, /no associated pointer/) end - it "taints the unpacked string" do - ["hello"].pack("p").unpack("p").first.tainted?.should be_true + ruby_version_is ''...'2.7' do + it "taints the unpacked string" do + ["hello"].pack("p").unpack("p").first.tainted?.should be_true + end end end diff --git a/spec/ruby/core/string/unpack/shared/taint.rb b/spec/ruby/core/string/unpack/shared/taint.rb index 391338192a..061a3e26ad 100644 --- a/spec/ruby/core/string/unpack/shared/taint.rb +++ b/spec/ruby/core/string/unpack/shared/taint.rb @@ -1,81 +1,83 @@ describe :string_unpack_taint, shared: true do - it "does not taint returned arrays if given an untainted format string" do - "".unpack(unpack_format(2)).tainted?.should be_false - end + ruby_version_is ''...'2.7' do + it "does not taint returned arrays if given an untainted format string" do + "".unpack(unpack_format(2)).tainted?.should be_false + end - it "does not taint returned arrays if given a tainted format string" do - format_string = unpack_format(2).dup - format_string.taint - "".unpack(format_string).tainted?.should be_false - end + it "does not taint returned arrays if given a tainted format string" do + format_string = unpack_format(2).dup + format_string.taint + "".unpack(format_string).tainted?.should be_false + end - it "does not taint returned strings if given an untainted format string" do - "".unpack(unpack_format(2)).any?(&:tainted?).should be_false - end + it "does not taint returned strings if given an untainted format string" do + "".unpack(unpack_format(2)).any?(&:tainted?).should be_false + end - it "does not taint returned strings if given a tainted format string" do - format_string = unpack_format(2).dup - format_string.taint - "".unpack(format_string).any?(&:tainted?).should be_false - end + it "does not taint returned strings if given a tainted format string" do + format_string = unpack_format(2).dup + format_string.taint + "".unpack(format_string).any?(&:tainted?).should be_false + end - it "does not taint returned arrays if given an untainted packed string" do - "".unpack(unpack_format(2)).tainted?.should be_false - end + it "does not taint returned arrays if given an untainted packed string" do + "".unpack(unpack_format(2)).tainted?.should be_false + end - it "does not taint returned arrays if given a tainted packed string" do - packed_string = "" - packed_string.taint - packed_string.unpack(unpack_format(2)).tainted?.should be_false - end + it "does not taint returned arrays if given a tainted packed string" do + packed_string = "" + packed_string.taint + packed_string.unpack(unpack_format(2)).tainted?.should be_false + end - it "does not taint returned strings if given an untainted packed string" do - "".unpack(unpack_format(2)).any?(&:tainted?).should be_false - end + it "does not taint returned strings if given an untainted packed string" do + "".unpack(unpack_format(2)).any?(&:tainted?).should be_false + end - it "taints returned strings if given a tainted packed string" do - packed_string = "" - packed_string.taint - packed_string.unpack(unpack_format(2)).all?(&:tainted?).should be_true - end + it "taints returned strings if given a tainted packed string" do + packed_string = "" + packed_string.taint + packed_string.unpack(unpack_format(2)).all?(&:tainted?).should be_true + end - it "does not untrust returned arrays if given an untrusted format string" do - "".unpack(unpack_format(2)).untrusted?.should be_false - end + it "does not untrust returned arrays if given an untrusted format string" do + "".unpack(unpack_format(2)).untrusted?.should be_false + end - it "does not untrust returned arrays if given a untrusted format string" do - format_string = unpack_format(2).dup - format_string.untrust - "".unpack(format_string).untrusted?.should be_false - end + it "does not untrust returned arrays if given a untrusted format string" do + format_string = unpack_format(2).dup + format_string.untrust + "".unpack(format_string).untrusted?.should be_false + end - it "does not untrust returned strings if given an untainted format string" do - "".unpack(unpack_format(2)).any?(&:untrusted?).should be_false - end + it "does not untrust returned strings if given an untainted format string" do + "".unpack(unpack_format(2)).any?(&:untrusted?).should be_false + end - it "does not untrust returned strings if given a untrusted format string" do - format_string = unpack_format(2).dup - format_string.untrust - "".unpack(format_string).any?(&:untrusted?).should be_false - end + it "does not untrust returned strings if given a untrusted format string" do + format_string = unpack_format(2).dup + format_string.untrust + "".unpack(format_string).any?(&:untrusted?).should be_false + end - it "does not untrust returned arrays if given an trusted packed string" do - "".unpack(unpack_format(2)).untrusted?.should be_false - end + it "does not untrust returned arrays if given an trusted packed string" do + "".unpack(unpack_format(2)).untrusted?.should be_false + end - it "does not untrust returned arrays if given a untrusted packed string" do - packed_string = "" - packed_string.untrust - packed_string.unpack(unpack_format(2)).untrusted?.should be_false - end + it "does not untrust returned arrays if given a untrusted packed string" do + packed_string = "" + packed_string.untrust + packed_string.unpack(unpack_format(2)).untrusted?.should be_false + end - it "does not untrust returned strings if given an trusted packed string" do - "".unpack(unpack_format(2)).any?(&:untrusted?).should be_false - end + it "does not untrust returned strings if given an trusted packed string" do + "".unpack(unpack_format(2)).any?(&:untrusted?).should be_false + end - it "untrusts returned strings if given a untrusted packed string" do - packed_string = "" - packed_string.untrust - packed_string.unpack(unpack_format(2)).all?(&:untrusted?).should be_true + it "untrusts returned strings if given a untrusted packed string" do + packed_string = "" + packed_string.untrust + packed_string.unpack(unpack_format(2)).all?(&:untrusted?).should be_true + end end end diff --git a/spec/ruby/core/string/upcase_spec.rb b/spec/ruby/core/string/upcase_spec.rb index 72aacd88a9..eb7d708fe0 100644 --- a/spec/ruby/core/string/upcase_spec.rb +++ b/spec/ruby/core/string/upcase_spec.rb @@ -65,10 +65,12 @@ describe "String#upcase" do -> { "abc".upcase(:invalid_option) }.should raise_error(ArgumentError) end - it "taints result when self is tainted" do - "".taint.upcase.tainted?.should == true - "X".taint.upcase.tainted?.should == true - "x".taint.upcase.tainted?.should == true + ruby_version_is ''...'2.7' do + it "taints result when self is tainted" do + "".taint.upcase.tainted?.should == true + "X".taint.upcase.tainted?.should == true + "x".taint.upcase.tainted?.should == true + end end it "returns a subclass instance for subclasses" do diff --git a/spec/ruby/core/symbol/shared/slice.rb b/spec/ruby/core/symbol/shared/slice.rb index 478e0d80ae..3f07f6aedb 100644 --- a/spec/ruby/core/symbol/shared/slice.rb +++ b/spec/ruby/core/symbol/shared/slice.rb @@ -191,12 +191,14 @@ describe :symbol_slice, shared: true do $~.should be_nil end - it "returns a tainted string if the regexp is tainted" do - :symbol.send(@method, /./.taint).tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "returns a tainted string if the regexp is tainted" do + :symbol.send(@method, /./.taint).tainted?.should be_true + end - it "returns an untrusted string if the regexp is untrusted" do - :symbol.send(@method, /./.untrust).untrusted?.should be_true + it "returns an untrusted string if the regexp is untrusted" do + :symbol.send(@method, /./.untrust).untrusted?.should be_true + end end end @@ -219,12 +221,14 @@ describe :symbol_slice, shared: true do :symbol.send(@method, /(sy)(mb)(ol)/, 1.5).should == "sy" end - it "returns a tainted string if the regexp is tainted" do - :symbol.send(@method, /(.)/.taint, 1).tainted?.should be_true - end + ruby_version_is ''...'2.7' do + it "returns a tainted string if the regexp is tainted" do + :symbol.send(@method, /(.)/.taint, 1).tainted?.should be_true + end - it "returns an untrusted string if the regexp is untrusted" do - :symbol.send(@method, /(.)/.untrust, 1).untrusted?.should be_true + it "returns an untrusted string if the regexp is untrusted" do + :symbol.send(@method, /(.)/.untrust, 1).untrusted?.should be_true + end end describe "and an index that cannot be converted to an Integer" do |