summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string
diff options
context:
space:
mode:
authorJeremy Evans <[email protected]>2019-09-24 20:59:12 -0700
committerJeremy Evans <[email protected]>2019-11-18 01:00:25 +0200
commitffd0820ab317542f8780aac475da590a4bdbc7a8 (patch)
tree6a5d774933c15fd2b9ea948bd3ae2fa587faaf82 /spec/ruby/core/string
parentc5c05460ac20abcbc0ed686eb4acf06da7a39a79 (diff)
Deprecate taint/trust and related methods, and make the methods no-ops
This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2476
Diffstat (limited to 'spec/ruby/core/string')
-rw-r--r--spec/ruby/core/string/b_spec.rb12
-rw-r--r--spec/ruby/core/string/capitalize_spec.rb8
-rw-r--r--spec/ruby/core/string/center_spec.rb24
-rw-r--r--spec/ruby/core/string/chomp_spec.rb66
-rw-r--r--spec/ruby/core/string/chop_spec.rb18
-rw-r--r--spec/ruby/core/string/crypt_spec.rb44
-rw-r--r--spec/ruby/core/string/delete_prefix_spec.rb8
-rw-r--r--spec/ruby/core/string/delete_spec.rb10
-rw-r--r--spec/ruby/core/string/delete_suffix_spec.rb8
-rw-r--r--spec/ruby/core/string/downcase_spec.rb10
-rw-r--r--spec/ruby/core/string/dump_spec.rb16
-rw-r--r--spec/ruby/core/string/element_set_spec.rb34
-rw-r--r--spec/ruby/core/string/gsub_spec.rb196
-rw-r--r--spec/ruby/core/string/insert_spec.rb18
-rw-r--r--spec/ruby/core/string/inspect_spec.rb16
-rw-r--r--spec/ruby/core/string/ljust_spec.rb24
-rw-r--r--spec/ruby/core/string/lstrip_spec.rb10
-rw-r--r--spec/ruby/core/string/modulo_spec.rb68
-rw-r--r--spec/ruby/core/string/plus_spec.rb16
-rw-r--r--spec/ruby/core/string/prepend_spec.rb12
-rw-r--r--spec/ruby/core/string/reverse_spec.rb8
-rw-r--r--spec/ruby/core/string/rjust_spec.rb24
-rw-r--r--spec/ruby/core/string/rstrip_spec.rb10
-rw-r--r--spec/ruby/core/string/scan_spec.rb56
-rw-r--r--spec/ruby/core/string/shared/chars.rb16
-rw-r--r--spec/ruby/core/string/shared/concat.rb16
-rw-r--r--spec/ruby/core/string/shared/each_line.rb8
-rw-r--r--spec/ruby/core/string/shared/replace.rb48
-rw-r--r--spec/ruby/core/string/shared/slice.rb150
-rw-r--r--spec/ruby/core/string/shared/succ.rb8
-rw-r--r--spec/ruby/core/string/shared/to_s.rb8
-rw-r--r--spec/ruby/core/string/slice_spec.rb108
-rw-r--r--spec/ruby/core/string/split_spec.rb58
-rw-r--r--spec/ruby/core/string/squeeze_spec.rb14
-rw-r--r--spec/ruby/core/string/strip_spec.rb10
-rw-r--r--spec/ruby/core/string/sub_spec.rb144
-rw-r--r--spec/ruby/core/string/swapcase_spec.rb8
-rw-r--r--spec/ruby/core/string/tr_s_spec.rb14
-rw-r--r--spec/ruby/core/string/tr_spec.rb14
-rw-r--r--spec/ruby/core/string/undump_spec.rb12
-rw-r--r--spec/ruby/core/string/unpack/p_spec.rb12
-rw-r--r--spec/ruby/core/string/unpack/shared/taint.rb128
-rw-r--r--spec/ruby/core/string/upcase_spec.rb10
43 files changed, 832 insertions, 670 deletions
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