summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string/gsub_spec.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-09-24 20:59:12 -0700
committerJeremy Evans <code@jeremyevans.net>2019-11-18 01:00:25 +0200
commitffd0820ab317542f8780aac475da590a4bdbc7a8 (patch)
tree6a5d774933c15fd2b9ea948bd3ae2fa587faaf82 /spec/ruby/core/string/gsub_spec.rb
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/gsub_spec.rb')
-rw-r--r--spec/ruby/core/string/gsub_spec.rb196
1 files changed, 104 insertions, 92 deletions
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