From a987a8e7c250568264e49b4b90a0a1760b15c67e Mon Sep 17 00:00:00 2001 From: Jonas Arvidsson Date: Sat, 25 Jan 2014 22:55:47 +0100 Subject: [PATCH] Fix bug in edit regarding file names with path but no suffix There was a bug in Command::Edit#probably_a_file? due to missing parentheses in a method call followed by an operator. --- CHANGELOG.md | 1 + lib/pry/commands/edit.rb | 2 +- spec/commands/edit_spec.rb | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ec1ea1c..b28c9195 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ being inferred from context (#877) * Rename `--installed-plugins` flag to `--plugins` * Strip ANSI codes from prompt before measuring length for indentation (#493) +* Fix bug in `edit` regarding recognition of file names without suffix. #### Dev-facing changes * `rake pry` now accepts switches prefixed with `_` (e.g., `rake pry _v`) diff --git a/lib/pry/commands/edit.rb b/lib/pry/commands/edit.rb index a3b55999..dd00c5ec 100644 --- a/lib/pry/commands/edit.rb +++ b/lib/pry/commands/edit.rb @@ -186,7 +186,7 @@ class Pry end def probably_a_file?(str) - [".rb", ".c", ".py", ".yml", ".gemspec"].include? File.extname(str) || + [".rb", ".c", ".py", ".yml", ".gemspec"].include?(File.extname(str)) || str =~ /\/|\\/ end diff --git a/spec/commands/edit_spec.rb b/spec/commands/edit_spec.rb index 5150aec4..fb7fee2f 100644 --- a/spec/commands/edit_spec.rb +++ b/spec/commands/edit_spec.rb @@ -35,6 +35,16 @@ describe "edit" do FileUtils.rm(@tf_path) if File.exists?(@tf_path) end + it "should not allow patching any known kind of file" do + ["file.rb", "file.c", "file.py", "file.yml", "file.gemspec", + "/tmp/file", "\\\\Temp\\\\file"].each do |file| + proc { + pry_eval "edit -p #{file}" + }.should.raise(NotImplementedError). + message.should =~ /Cannot yet patch false objects!/ + end + end + it "should invoke Pry.config.editor with absolutified filenames" do pry_eval 'edit lib/pry.rb' @file.should == File.expand_path('lib/pry.rb')