summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string/slice_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/string/slice_spec.rb')
-rw-r--r--spec/ruby/core/string/slice_spec.rb108
1 files changed, 59 insertions, 49 deletions
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