Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit c019137

Browse files
committed
Remove $SAFE support for 2.7
1 parent 8fe0fe7 commit c019137

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

spec/rspec/core/formatters/html_snippet_extractor_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ module Formatters
1212
expect(RSpec::Core::Formatters::HtmlSnippetExtractor.new.lines_around("blech", 8)).to eq("# Couldn't get snippet for blech")
1313
end
1414

15-
it "falls back on a default message when it gets a security error" do
16-
message = with_safe_set_to_level_that_triggers_security_errors do
17-
RSpec::Core::Formatters::HtmlSnippetExtractor.new.lines_around("blech".dup.taint, 8)
15+
if RSpec::Support::RubyFeatures.supports_taint?
16+
it "falls back on a default message when it gets a security error" do
17+
message = with_safe_set_to_level_that_triggers_security_errors do
18+
RSpec::Core::Formatters::HtmlSnippetExtractor.new.lines_around("blech".dup.taint, 8)
19+
end
20+
expect(message).to eq("# Couldn't get snippet for blech")
1821
end
19-
expect(message).to eq("# Couldn't get snippet for blech")
2022
end
2123

2224
describe "snippet extraction" do

spec/support/helper_methods.rb

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,32 @@ def ignoring_warnings
1414
result
1515
end
1616

17-
def with_safe_set_to_level_that_triggers_security_errors
18-
result = nil
17+
# In Ruby 2.7 taint was removed and has no effect, whilst SAFE warns that it
18+
# has no effect and will become a normal varible in 3.0.
19+
if RUBY_VERSION >= '2.7'
20+
def with_safe_set_to_level_that_triggers_security_errors
21+
yield
22+
end
23+
else
24+
def with_safe_set_to_level_that_triggers_security_errors
25+
result = nil
1926

20-
orig_safe = $SAFE
21-
Thread.new do
22-
ignoring_warnings { $SAFE = SAFE_LEVEL_THAT_TRIGGERS_SECURITY_ERRORS }
23-
result = yield
24-
end.join
27+
orig_safe = $SAFE
28+
Thread.new do
29+
ignoring_warnings { $SAFE = SAFE_LEVEL_THAT_TRIGGERS_SECURITY_ERRORS }
30+
result = yield
31+
end.join
2532

26-
# $SAFE is not supported on Rubinius
27-
# In Ruby 2.6, $SAFE became a global variable; previously it was local to a thread.
28-
unless defined?(Rubinius) || SAFE_IS_GLOBAL_VARIABLE
29-
# $SAFE should not have changed in this thread.
30-
expect($SAFE).to eql orig_safe
31-
end
33+
# $SAFE is not supported on Rubinius
34+
# In Ruby 2.6, $SAFE became a global variable; previously it was local to a thread.
35+
unless defined?(Rubinius) || SAFE_IS_GLOBAL_VARIABLE
36+
# $SAFE should not have changed in this thread.
37+
expect($SAFE).to eql orig_safe
38+
end
3239

33-
result
34-
ensure
35-
$SAFE = orig_safe if orig_safe && SAFE_IS_GLOBAL_VARIABLE
40+
result
41+
ensure
42+
$SAFE = orig_safe if orig_safe && SAFE_IS_GLOBAL_VARIABLE
43+
end
3644
end
3745
end

0 commit comments

Comments
 (0)