diff options
Diffstat (limited to 'spec/ruby/core/string/shared')
-rw-r--r-- | spec/ruby/core/string/shared/chars.rb | 16 | ||||
-rw-r--r-- | spec/ruby/core/string/shared/concat.rb | 16 | ||||
-rw-r--r-- | spec/ruby/core/string/shared/each_line.rb | 8 | ||||
-rw-r--r-- | spec/ruby/core/string/shared/replace.rb | 48 | ||||
-rw-r--r-- | spec/ruby/core/string/shared/slice.rb | 150 | ||||
-rw-r--r-- | spec/ruby/core/string/shared/succ.rb | 8 | ||||
-rw-r--r-- | spec/ruby/core/string/shared/to_s.rb | 8 |
7 files changed, 139 insertions, 115 deletions
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 |