summaryrefslogtreecommitdiff
path: root/lib/pry
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2020-03-17 18:02:58 +0800
committerKyrylo Silin <silin@kyrylo.org>2020-03-17 18:04:26 +0800
commitbe870b780d802001b399a2cc2f143df69529dcc8 (patch)
tree29bd81105ceb442a04ca03fec37ce460a4332854 /lib/pry
parentd8deccde68d4fdc47b301fd63abfedcf19ecdbc7 (diff)
downloadpry-be870b780d802001b399a2cc2f143df69529dcc8.tar.gz
exceptions: check if $SAFE is supported by Ruby
Fixes #2099 ($SAFE will become a normal global variable in Ruby 3.0) MRI < 2.7 supports `$SAFE` variable, which is associated with taint/untaint methods. All of that is deprecated in 2.7 with a lot of warning messages generated, and no other effect. None of this is supported on other Ruby platforms. Related Ruby ticket: https://bugs.ruby-lang.org/issues/8468
Diffstat (limited to 'lib/pry')
-rw-r--r--lib/pry/exceptions.rb6
-rw-r--r--lib/pry/pry_class.rb7
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/pry/exceptions.rb b/lib/pry/exceptions.rb
index eac1c009..ee31e6c4 100644
--- a/lib/pry/exceptions.rb
+++ b/lib/pry/exceptions.rb
@@ -27,7 +27,11 @@ class Pry
# 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
diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb
index 414c6a5a..80dda807 100644
--- a/lib/pry/pry_class.rb
+++ b/lib/pry/pry_class.rb
@@ -6,6 +6,13 @@ require 'pathname'
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