wincent / command-t

⌨️ Fast file navigation for Neovim and Vim
BSD 2-Clause "Simplified" License
2.74k stars 317 forks source link

I can not open a file that contains LF in the name #365

Closed rkuchumov closed 4 years ago

rkuchumov commented 4 years ago

When I create a file that contains LF:

echo aaa > "$(printf 'aa\nbb')"

I can not use command-t to open it:

Error detected while processing function commandt#private#AcceptSelection[1]..commandt#GotoOrOpen:
line   11:
E492: Not an editor command: bb

One of the workaround that I've found is to use :edit **/* instead of command-t

wincent commented 4 years ago

Can probably fix this, although it might be the kind of thing that is very susceptible to platform differences. I also wonder how sane it is to create/use files with newlines in their names. Do you really have such files in your use case?

wincent commented 4 years ago

Something like this will probably do it; works for me locally at least. Care to try it on your system @rkuchumov?

diff --git a/ruby/command-t/lib/command-t/controller.rb b/ruby/command-t/lib/command-t/controller.rb
index 6f0187b..ebded6a 100644
--- a/ruby/command-t/lib/command-t/controller.rb
+++ b/ruby/command-t/lib/command-t/controller.rb
@@ -416,7 +416,7 @@ def case_sensitive?
     def sanitize_path_string(str)
       # for details on escaping command-line mode arguments see: :h :
       # (that is, help on ":") in the Vim documentation.
-      str.gsub(/[ \\|%#"]/, '\\\\\0')
+      str.gsub(/[ \n\\|%#"]/, '\\\\\0')
     end

     def current_buffer_visible_in_other_window
wincent commented 4 years ago

Probably a better/safer fix:

diff --git a/ruby/command-t/lib/command-t/controller.rb b/ruby/command-t/lib/command-t/controller.rb
index 6f0187b..0323d54 100644
--- a/ruby/command-t/lib/command-t/controller.rb
+++ b/ruby/command-t/lib/command-t/controller.rb
@@ -412,11 +412,9 @@ def case_sensitive?
       false
     end

-    # Backslash-escape space, \, |, %, #, "
+    # Backslash-escape space, \, |, %, #, " etc.
     def sanitize_path_string(str)
-      # for details on escaping command-line mode arguments see: :h :
-      # (that is, help on ":") in the Vim documentation.
-      str.gsub(/[ \\|%#"]/, '\\\\\0')
+      ::VIM::evaluate("fnameescape('#{str}')")
     end

     def current_buffer_visible_in_other_window
rkuchumov commented 4 years ago

The last one works, thanks! Majority of file systems allow to have any character in the file name except for 0-byte and slash. So files with any control charter may appear in FS.