Edit: handle blanks in filenames correctly

Also, move path escaping to `Editor` class. The test is currently
failing (looks like a bug in `Editor`).
This commit is contained in:
Kyrylo Silin 2013-01-13 23:09:09 +02:00 committed by John Mair
parent 5871054c05
commit e66d2083c1
3 changed files with 12 additions and 6 deletions

View File

@ -114,11 +114,8 @@ class Pry
ensure_file_name_is_valid(file_name)
# Sanitize blanks.
sanitized_file_name = Shellwords.escape(file_name)
Pry::Editor.invoke_editor(sanitized_file_name, line, reload?(file_name))
set_file_and_dir_locals(sanitized_file_name)
Pry::Editor.invoke_editor(file_name, line, reload?(file_name))
set_file_and_dir_locals(file_name)
if reload?(file_name)
silence_warnings do
@ -128,7 +125,7 @@ class Pry
end
def filename_argument
args.first || ""
args.join(' ')
end
def code_object

View File

@ -33,6 +33,9 @@ class Pry
# all the flags we want as well as the file and line number we
# want to open at.
def build_editor_invocation_string(file, line, blocking)
# Sanitize blanks.
file = Shellwords.escape(file)
if Pry.config.editor.respond_to?(:call)
args = [file, line, blocking][0...(Pry.config.editor.arity)]
Pry.config.editor.call(*args)

View File

@ -39,6 +39,12 @@ describe "edit" do
File.exist?(@file).should == true
end
it "works with files that contain blanks in their names" do
FileUtils.touch '/tmp/hello world.rb'
pry_eval 'edit /tmp/hello world.rb'
@file.should == '/tmp/hello world.rb'
end
describe do
before do
Pad.counter = 0