Skip to content

Commit

Permalink
Merge pull request #2107 from pry/2099-safe-global-fix
Browse files Browse the repository at this point in the history
exceptions: check if $SAFE is supported by Ruby
  • Loading branch information
kyrylo committed Mar 17, 2020
2 parents d8deccd + be870b7 commit c7b0d4a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
are set, Pry no longer uses traditional files like `~/.pryrc` &
`~/.pry_history`. Instead, the env variable paths are loaded first
([#2056](https://github.com/pry/pry/pull/2056))
* Fixed the `$SAFE will become a normal global variable in Ruby 3.0` warning on
Ruby 2.7 ([#2107](https://github.com/pry/pry/pull/2107))

### [v0.12.2][v0.12.2] (November 12, 2018)

Expand Down
6 changes: 5 additions & 1 deletion lib/pry/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def self.===(exception)
# Catches SecurityErrors if $SAFE is set
module TooSafeException
def self.===(exception)
$SAFE > 0 && exception.is_a?(SecurityError)
if Pry::HAS_SAFE_LEVEL
$SAFE > 0 && exception.is_a?(SecurityError)
else
exception.is_a?(SecurityError)
end
end
end

Expand Down
7 changes: 7 additions & 0 deletions lib/pry/pry_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
class Pry
LOCAL_RC_FILE = "./.pryrc".freeze

# @return [Boolean] true if this Ruby supports safe levels and tainting,
# to guard against using deprecated or unsupported features
HAS_SAFE_LEVEL = (
RUBY_ENGINE == 'ruby' &&
Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7')
)

class << self
extend Pry::Forwardable
attr_accessor :custom_completions
Expand Down

0 comments on commit c7b0d4a

Please sign in to comment.