summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mair <jrmair@gmail.com>2017-11-14 00:02:15 +0100
committerGitHub <noreply@github.com>2017-11-14 00:02:15 +0100
commitabd4041a91fa52235937ffe754f62bcdf6416dd2 (patch)
tree0f3a414835fe2597870143755e2b71ea75b5dd53
parent887ee4811e706960659b1d74ee6af2ad038aee7b (diff)
parentdc343306a7c50247fe98fbe54741a321164c9cf2 (diff)
downloadpry-0-11-stable.tar.gz
Merge pull request #1699 from r-obert/0-11-30-11-stable
v0.11.3
-rw-r--r--CHANGELOG.md21
-rw-r--r--lib/pry/config/behavior.rb1
-rw-r--r--lib/pry/helpers/text.rb15
-rw-r--r--lib/pry/method/weird_method_locator.rb21
-rw-r--r--spec/config_spec.rb15
-rw-r--r--spec/integration/hanami_spec.rb38
-rw-r--r--spec/integration/readline_spec.rb (renamed from spec/regression/readline_spec.rb)6
7 files changed, 96 insertions, 21 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c7ad10e1..4cc04694 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,24 @@
+### 0.11.3
+
+* Fix a case of infinite recursion in `Pry::Method::WeirdMethodLocator#find_method_in_superclass`
+ that users of the [Hanami](http://hanamirb.org/) web framework experienced and reported
+ since 2015.
+
+See pull request [#1639](https://github.com/pry/pry/pull/1689).
+
+* Fix a bug where Method objects were not returned for setters inherited
+ from a default (Pry::Config::Default). Eg, this is no longer an error:
+
+ pry(main)> d = Pry::Config.from_hash({}, Pry::Config::Default.new)
+ pry(main)> d.method(:exception_whitelist=) # Error
+
+See pull request [#1688](https://github.com/pry/pry/pull/1688).
+
+* Do not capture unused Proc objects in Text helper methods `no_color` and `no_paging`,
+ for performance reasons. Improve the documentation of both methods.
+
+See pull request [#1691](https://github.com/pry/pry/pull/1691).
+
### 0.11.2
* Fix a NoMethodError in the deprecated method stagger_output.
diff --git a/lib/pry/config/behavior.rb b/lib/pry/config/behavior.rb
index f487637d..ec078ced 100644
--- a/lib/pry/config/behavior.rb
+++ b/lib/pry/config/behavior.rb
@@ -188,6 +188,7 @@ module Pry::Config::Behavior
end
def respond_to_missing?(key, include_all=false)
+ key = key.to_s.chomp(ASSIGNMENT)
key?(key) or @default.respond_to?(key) or super(key, include_all)
end
diff --git a/lib/pry/helpers/text.rb b/lib/pry/helpers/text.rb
index 22aecccd..a3170155 100644
--- a/lib/pry/helpers/text.rb
+++ b/lib/pry/helpers/text.rb
@@ -52,10 +52,13 @@ class Pry
end
alias_method :bright_default, :bold
- # Executes the block with `Pry.config.color` set to false.
+ #
# @yield
+ # Yields a block with color turned off.
+ #
# @return [void]
- def no_color(&block)
+ #
+ def no_color
boolean = Pry.config.color
Pry.config.color = false
yield
@@ -63,10 +66,13 @@ class Pry
Pry.config.color = boolean
end
- # Executes the block with `Pry.config.pager` set to false.
+ #
# @yield
+ # Yields a block with paging turned off.
+ #
# @return [void]
- def no_pager(&block)
+ #
+ def no_pager
boolean = Pry.config.pager
Pry.config.pager = false
yield
@@ -98,4 +104,3 @@ class Pry
end
end
end
-
diff --git a/lib/pry/method/weird_method_locator.rb b/lib/pry/method/weird_method_locator.rb
index 08c0a361..fee19dac 100644
--- a/lib/pry/method/weird_method_locator.rb
+++ b/lib/pry/method/weird_method_locator.rb
@@ -26,13 +26,17 @@ class Pry
# @param [Binding] b
# @return [Boolean]
def normal_method?(method, b)
- method && (method.source_file && method.source_range rescue false) &&
- File.expand_path(method.source_file) == File.expand_path(b.eval('__FILE__')) &&
- method.source_range.include?(b.eval('__LINE__'))
+ if method and method.source_file and method.source_range
+ binding_file, binding_line = b.eval('__FILE__'), b.eval('__LINE__')
+ File.expand_path(method.source_file) == File.expand_path(binding_file) and
+ method.source_range.include?(binding_line)
+ end
+ rescue
+ false
end
def weird_method?(method, b)
- !normal_method?(method, b)
+ not normal_method?(method, b)
end
end
@@ -61,6 +65,11 @@ class Pry
private
+ def skip_superclass_search?
+ target_mod = @target.eval('self').class
+ target_mod.ancestors.take_while {|mod| mod != target_mod }.any?
+ end
+
def normal_method?(method)
self.class.normal_method?(method, target)
end
@@ -98,7 +107,9 @@ class Pry
# superclass method.
def find_method_in_superclass
guess = method
-
+ if skip_superclass_search?
+ return guess
+ end
while guess
# needs rescue if this is a Disowned method or a C method or something...
# TODO: Fix up the exception handling so we don't need a bare rescue
diff --git a/spec/config_spec.rb b/spec/config_spec.rb
index d6961c80..3066fcef 100644
--- a/spec/config_spec.rb
+++ b/spec/config_spec.rb
@@ -45,7 +45,7 @@ describe Pry::Config do
expect(local3.foo).to eq(21)
end
- it "stores a local copy of the parent's hooks upon accessing them" do
+ it "stores a local copy of the parents hooks upon accessing them" do
parent = Pry::Config.from_hash(hooks: "parent_hooks")
local = Pry::Config.new parent
local.hooks.gsub! 'parent', 'local'
@@ -67,13 +67,7 @@ describe Pry::Config do
end
it "recursively builds Pry::Config objects from a Hash" do
- h = {
- 'foo1' => {
- 'foo2' => {
- 'foo3' => 'foobar'
- }
- }
- }
+ h = {'foo1' => {'foo2' => {'foo3' => 'foobar'}}}
default = Pry::Config.from_hash(h)
expect(default.foo1).to be_instance_of(described_class)
expect(default.foo1.foo2).to be_instance_of(described_class)
@@ -92,6 +86,11 @@ describe Pry::Config do
expect(method_obj.name).to eq :key
expect(method_obj.call).to eq(1)
end
+
+ it "returns a Method object for a setter on a parent" do
+ config = described_class.from_hash({}, described_class.from_hash(foo: 1))
+ expect(config.method(:foo=)).to be_an_instance_of(Method)
+ end
end
describe "#respond_to?" do
diff --git a/spec/integration/hanami_spec.rb b/spec/integration/hanami_spec.rb
new file mode 100644
index 00000000..9ec7a030
--- /dev/null
+++ b/spec/integration/hanami_spec.rb
@@ -0,0 +1,38 @@
+require "helper"
+require "shellwords"
+
+RSpec.describe "Hanami integration" do
+ before :all do
+ @ruby = RbConfig.ruby.shellescape
+ @pry_dir = File.expand_path(File.join(__FILE__, '../../../lib')).shellescape
+ end
+
+ it "does not enter an infinite loop (#1471, #1621)" do
+ skip "prepend is not supported on this version of Ruby" if RUBY_VERSION.start_with? "1.9"
+ code = <<-RUBY
+ require "pry"
+ require "timeout"
+ module Prepend1
+ def call(arg)
+ super
+ end
+ end
+ module Prepend2
+ def call(arg)
+ super
+ end
+ end
+ class Action
+ prepend Prepend1
+ prepend Prepend2
+ def call(arg)
+ binding.pry input: StringIO.new("exit"), output: StringIO.new
+ end
+ end
+ Timeout.timeout(1) { Action.new.call("define prison, in the abstract sense") }
+ exit 42
+ RUBY
+ `#@ruby -I#@pry_dir -e'#{code}'`
+ expect($?.exitstatus).to eq(42)
+ end
+end
diff --git a/spec/regression/readline_spec.rb b/spec/integration/readline_spec.rb
index 19dad754..201e37f9 100644
--- a/spec/regression/readline_spec.rb
+++ b/spec/integration/readline_spec.rb
@@ -4,9 +4,9 @@
require "helper"
require "shellwords"
-describe "Readline" do
- before do
- @ruby = RbConfig.ruby.shellescape
+RSpec.describe "Readline" do
+ before :all do
+ @ruby = RbConfig.ruby.shellescape
@pry_dir = File.expand_path(File.join(__FILE__, '../../../lib')).shellescape
end