Quote paths with double quotes not single quotes#148
Quote paths with double quotes not single quotes#148madscientist wants to merge 3 commits intojbardin:masterfrom
Conversation
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 jbardin#138 and issue jbardin#147
|
I'm surprised not to see backslashes in the list, is that correct? |
|
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, 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 I will post an update to handle this. |
POSIX double-quoted strings don't require backslash characters to be escaped _unless_ they are escaping a special character. So, for a filename foo\bar the quoting can be "foo\bar". But for a filename such as foo\$bar the quoting must be "foo\\\$bar". Prefer to avoid escaping backslashes if not necessary to be more compatible with Windows paths.
|
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 :) |
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