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

Commit 3fbdd56

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

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

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)