scp.py icon indicating copy to clipboard operation
scp.py copied to clipboard

Quote paths with double quotes not single quotes

Open madscientist opened this issue 4 years ago • 3 comments

The previous scp single-quote algorithm for pathnames worked well for POSIX servers but had problems on Windows servers, where single quotes are not recognized (just treated like normal characters).

Use double quotes instead, and implement proper double-quoted escaping for POSIX strings. This gives 100% correct paths on POSIX servers but could still yield incorrect paths on Windows if the path contains unusual characters like $ or `. If the user requires 100% Windows compatibility they'll need to provide their own sanitizer function when communicating with a Windows server.

Addresses issue #138 and issue #147

madscientist avatar Dec 04 '20 01:12 madscientist

I'm surprised not to see backslashes in the list, is that correct?

remram44 avatar Dec 04 '20 01:12 remram44

Within a double-quoted string backslashes do not need to be escaped unless they are escaping a special character. See the POSIX spec link I put into the code review. So, for example, echo "foo\bar" will print out the string foo\bar: no need to escape the backslash.

However, you're right that my solution is missing something because I need to handle backslashes that DO come before special characters. In other words, say I have the literal filename foo\$bar (that is, the backslash is part of the filename). My previous solution would turn this into "foo\\$bar" which is clearly not right: it needs to be "foo\\\$bar" (escape the backslash, then escape the $).

I will post an update to handle this.

madscientist avatar Dec 04 '20 07:12 madscientist

Just to point out, we should probably provide an update to the README that mentions this portability concern for pathnames when talking to Windows servers and suggests a sanitizer function.

We could even provide a default sanitizer function for Windows servers so users could just choose that, if any of us feels sufficiently knowledgeable as to write one :)

madscientist avatar Dec 04 '20 17:12 madscientist