mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
only interpolate once during command processing (fixes #200)
This commit is contained in:
parent
39df59402b
commit
61fdb7150e
3 changed files with 19 additions and 12 deletions
|
@ -53,23 +53,20 @@ class Pry
|
|||
# interpolation against.
|
||||
# @return [Array] The command data and arg string pair
|
||||
def command_matched(val, target)
|
||||
_, cmd_data = commands.commands.find do |name, data|
|
||||
interpolated_val = begin
|
||||
interpolate_string(val, target)
|
||||
rescue Exception
|
||||
nil
|
||||
end
|
||||
|
||||
_, cmd_data = commands.commands.find do |name, data|
|
||||
prefix = convert_to_regex(Pry.config.command_prefix)
|
||||
prefix = "(?:#{prefix})?" unless data.options[:use_prefix]
|
||||
|
||||
command_regex = /^#{prefix}#{convert_to_regex(name)}(?!\S)/
|
||||
|
||||
if data.options[:interpolate]
|
||||
# If interpolation fails then the command cannot be matched,
|
||||
# so early exit.
|
||||
begin
|
||||
interp_val = interpolate_string(val, target)
|
||||
rescue Exception
|
||||
next
|
||||
end
|
||||
|
||||
val.replace interp_val if command_regex =~ interp_val
|
||||
val.replace interpolated_val if command_regex =~ interpolated_val
|
||||
else
|
||||
command_regex =~ val
|
||||
end
|
||||
|
|
|
@ -245,11 +245,21 @@ describe "Pry::CommandProcessor" do
|
|||
end
|
||||
|
||||
|
||||
it 'commands that have :interpolate => false should not be interpolated (interpolate_string should *not* be called)' do
|
||||
it 'should not interpolate commands that have :interpolate => false (interpolate_string should *not* be called)' do
|
||||
@pry.commands.command("boast", "", :interpolate => false) {}
|
||||
|
||||
# remember to use '' instead of "" when testing interpolation or
|
||||
# you'll cause yourself incredible confusion
|
||||
lambda { @command_processor.command_matched('boast #{c}', binding) }.should.not.raise NameError
|
||||
end
|
||||
|
||||
it 'should only execute the contents of an interpolation once' do
|
||||
$obj = 'a'
|
||||
|
||||
redirect_pry_io(InputTester.new('#{$obj.succ!}'), StringIO.new) do
|
||||
Pry.new.rep
|
||||
end
|
||||
|
||||
$obj.should == 'b'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -517,7 +517,7 @@ describe Pry do
|
|||
$test_interpolation = nil
|
||||
end
|
||||
|
||||
# bug fix for https://github.com/banister/pry/issues/170
|
||||
# bug fix for https://github.com/pry/pry/issues/170
|
||||
it 'should not choke on complex string interpolation when checking if ruby code is a command' do
|
||||
redirect_pry_io(InputTester.new('/#{Regexp.escape(File.expand_path("."))}/'), str_output = StringIO.new) do
|
||||
pry
|
||||
|
|
Loading…
Add table
Reference in a new issue