1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Fix regression with respect to space prefixes

Fixes #1369 (Prefixing commands with a space is not working)

The regression was introduced by this commit:

  68bcca22a0

Since then the main logic for the REPL was hugely refactored. This
refactoring morphed the error into this commit:

  e020f8cecd

Sorry about this hacky solution.
This commit is contained in:
Kyrylo Silin 2015-03-08 08:41:48 +02:00
parent 65fdcba0d9
commit dd92e2a359
4 changed files with 20 additions and 2 deletions

View file

@ -14,6 +14,7 @@
* Fixed the "uninitialized constant Pry::ObjectPath::StringScanner" exception during autocomplete ([#1330](https://github.com/pry/pry/issues/1330))
* Secured usage of colours with special characters (RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE) in Pry::Helpers::Text ([#493](https://github.com/pry/pry/issues/493#issuecomment-39232771))
* Fixed regression with `pry -e` when it messes the terminal ([#1387](https://github.com/pry/pry/issues/1387))
* Fixed regression with space prefixes of expressions ([#1369](https://github.com/pry/pry/issues/1369))
### 0.10.1

View file

@ -269,7 +269,7 @@ class Pry
@suppress_output = false
inject_sticky_locals!
begin
if !process_command_safely(line.lstrip)
if !process_command_safely(line)
@eval_string << "#{line.chomp}\n" if !line.empty? || !@eval_string.empty?
end
rescue RescuableException => e
@ -400,6 +400,7 @@ class Pry
# @param [String] val The line to process.
# @return [Boolean] `true` if `val` is a command, `false` otherwise
def process_command(val)
val = val.lstrip if /^\s\S/ !~ val
val = val.chomp
result = commands.process_line(val,
:target => current_binding,

View file

@ -121,7 +121,10 @@ class PryTester
result = nil
strs.flatten.each do |str|
str = "#{str.strip}\n"
# Check for space prefix. See #1369.
if str !~ /^\s\S/
str = "#{str.strip}\n"
end
@history.push str if @history
if @pry.process_command(str)

View file

@ -99,4 +99,17 @@ describe "The whole thing" do
end
end
describe "space prefix" do
describe "with 1 space" do
it "it prioritizes variables over commands" do
expect(pry_eval(' ls = 2+2', ' ls')).to eq(4)
end
end
describe "with more than 1 space" do
it "prioritizes commands over variables" do
expect(mock_pry(' ls = 2+2')).to match(/SyntaxError.+unexpected '='/)
end
end
end
end