Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rkuchumov opened this issue Nov 30, 2019 · 4 comments
Closed

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

rkuchumov opened this issue Nov 30, 2019 · 4 comments

Comments

@rkuchumov
Copy link

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
Copy link
Owner

wincent commented Nov 30, 2019

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
Copy link
Owner

wincent commented Nov 30, 2019

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
Copy link
Owner

wincent commented Nov 30, 2019

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants