aurora / rmate

Remote TextMate 2 implemented as shell script
GNU General Public License v3.0
887 stars 123 forks source link

A filename with the literal string " ->" in it renders a file impossible to open. #57

Closed fake-name closed 7 years ago

fake-name commented 7 years ago

I have a remote file named img 1497837265 - ['Chip-ID' -> 'ESP8266-1175d8', 'Voltage-In' -> '785.00'].jpg. (Sublime text can view images, so it's convenient to check images using rmate).

Attempting to open this file via rmate fails:

durr@graphical:~/meterocr/UtiliCam/Server/images$ rmate "img 1497837263 - ['Chip-ID' -> 'ESP8266-1175d8', 'Voltage-In' -> '785.00'].jpg"
dirname: invalid option -- '>'
Try 'dirname --help' for more information.
ls: cannot access '/home/durr/img 1497837263 - ['\''Chip-ID'\'' -> '\''ESP8266-1175d8'\'', '\''Voltage-In'\'' -> '\''785.00'\''].jpg': No such file or directory
cat: '/home/durr/img 1497837263 - ['\''Chip-ID'\'' -> '\''ESP8266-1175d8'\'', '\''Voltage-In'\'' -> '\''785.00'\''].jpg': No such file or directory
durr@graphical:~/meterocr/UtiliCam/Server/images$ rmate img\ 1497837263\ -\ \[\'Chip-ID\'\ -\>\ \'ESP8266-1175d8\'\,\ \'Voltage-In\'\ -\>\ \'785.00\'\].jpg
dirname: invalid option -- '>'
Try 'dirname --help' for more information.
ls: cannot access '/home/durr/img 1497837263 - ['\''Chip-ID'\'' -> '\''ESP8266-1175d8'\'', '\''Voltage-In'\'' -> '\''785.00'\''].jpg': No such file or directory
cat: '/home/durr/img 1497837263 - ['\''Chip-ID'\'' -> '\''ESP8266-1175d8'\'', '\''Voltage-In'\'' -> '\''785.00'\''].jpg': No such file or directory
durr@graphical:~/meterocr/UtiliCam/Server/images$

This is trying to either use double-quotes around the entire filename, or the shell's (bash, in my case) automatically escaped filename.

Both these filenames are correct:

durr@graphical:~/meterocr/UtiliCam/Server/images$ file "img 1497837263 - ['Chip-ID' -> 'ESP8266-1175d8', 'Voltage-In' -> '785.00'].jpg"
img 1497837263 - ['Chip-ID' -> 'ESP8266-1175d8', 'Voltage-In' -> '785.00'].jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), density 0x0, segment length 16, baseline, precision 8, 1600x1200, frames 3
durr@graphical:~/meterocr/UtiliCam/Server/images$ file img\ 1497837263\ -\ \[\'Chip-ID\'\ -\>\ \'ESP8266-1175d8\'\,\ \'Voltage-In\'\ -\>\ \'785.00\'\].jpg
img 1497837263 - ['Chip-ID' -> 'ESP8266-1175d8', 'Voltage-In' -> '785.00'].jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), density 0x0, segment length 16, baseline, precision 8, 1600x1200, frames 3

Something being done to the filename inside the rmate script is broken by this string, somehow.

The minimal case of this issue is


durr@graphical:~/meterocr/UtiliCam/Server/images$ rmate "test ->.txt"
dirname: invalid option -- '>'
Try 'dirname --help' for more information.
aurora commented 7 years ago

Thanks for reporting this bug, i'll have a look into it.

fake-name commented 7 years ago

It's definitely a pretty silly problem, but I figure it might be exposing a potential issue internally somewhere.

aurora commented 7 years ago

Yes, you are right regarding the potential issue but there could always be the case that you have a - in your filename, eg. as leading character, which currently doesn't work either. With fixing the bug you found i also want to implement the possibility to use -- (double-dash) to end argument parsing, to make it possible to eg. open the file -foo by running

rmate -- -foo
aurora commented 7 years ago

I have created a test-branch https://github.com/aurora/rmate/tree/issue-57 ... can you try if this works for your case? It now seems to handle stuff like "test ->.txt", etc. just fine ...

aurora commented 7 years ago

I think this should work now @fake-name . The problem turned out to be the whitespaces in your filename which i didn't handle properly in a part of the script. Tried with your simplified test-case and also with the long (somehow obscure) filename you mentioned in your first post.

fake-name commented 7 years ago

Cool, thanks.

I wound up rewriting some of my stuff to not use angle brackets, so I kind of worked around the issue. They break on windows anyways, so it was kind of silly. I was basically embedding json in a filename because I haven't set up a proper database for a project, yet.