Skip to content

Commit 9a234e0

Browse files
committed
[GR-18163] Add $SAFE access warning
PullRequest: truffleruby/2195
2 parents c477a66 + a94e812 commit 9a234e0

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

spec/tags/language/safe_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ fails:The $SAFE variable can be manually lowered
1515
fails:The $SAFE variable is not Proc local
1616
fails:The $SAFE variable is not lambda local
1717
fails:The $SAFE variable is global like regular global variables
18-
fails:The $SAFE variable warn when access
1918
fails:The $SAFE variable warn when set

spec/tags/truffle/safe_tags.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
slow:The $SAFE variable does not warn when set to 0 and remembers the value
1+
slow:The $SAFE variable warns when set to 0 and remembers the value

spec/truffle/safe_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
require_relative '../ruby/spec_helper'
1010

1111
describe "The $SAFE variable" do
12-
it "does not warn when set to 0 and remembers the value" do
13-
ruby_exe("$SAFE = 0; puts $SAFE; puts Thread.current.safe_level", args: "2>&1").should == "0\n0\n"
12+
it "warns when set to 0 and remembers the value" do
13+
ruby_exe("$SAFE = 0; puts $SAFE; puts Thread.current.safe_level", args: "2>&1").should include("warning: $SAFE will become a normal global variable in Ruby 3.0\n0\n0\n")
1414
end
1515

1616
it "raises an error when set to 1" do

src/main/ruby/truffleruby/core/thread.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,10 @@ def marshal_dump
371371

372372
Truffle::KernelOperations.define_hooked_variable(
373373
:$SAFE,
374-
-> { Thread.current.safe_level },
374+
-> {
375+
warn '$SAFE will become a normal global variable in Ruby 3.0', uplevel: 1
376+
Thread.current.safe_level
377+
},
375378
-> level {
376379
raise SecurityError, 'Setting $SAFE is no longer supported.' unless level == 0
377380
}

0 commit comments

Comments
 (0)