8000 Escape with double quotes instead of single quotes by remram44 · Pull Request #139 · jbardin/scp.py · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Escape with double quotes instead of single quotes #139

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions scp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,27 @@
import types


# this is quote from the shlex module, added in py3.3
_find_unsafe = re.compile(br'[^\w@%+=:,./~-]').search
safe_shell_chars = set(b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
b"abcdefghijklmnopqrstuvwxyz" +
b"0123456789" +
b"-+=/:.,%_")


def _sh_quote(s):
"""Return a shell-escaped version of the string `s`."""
if not s:
return b""
if _find_unsafe(s) is None:
r"""Given bl"a, returns "bl\\"a".
"""
if not s or any(c not in safe_shell_chars for c in s):
return (
b'"' +
s.replace(b'\\', b'\\\\')
.replace(b'"', b'\\"')
.replace(b'`', b'\\`')
.replace(b'$', b'\\$') +
b'"'
)
else:
return s

# use single quotes, and put single quotes into double quotes
# the string $'b is then quoted as '$'"'"'b'
return b"'" + s.replace(b"'", b"'\"'\"'") + b"'"


# Unicode conversion functions; assume UTF-8

Expand Down
0