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

single quotes not properly escaped #34

Open
sanderhahn opened this issue Jul 16, 2019 · 1 comment
Open

single quotes not properly escaped #34

sanderhahn opened this issue Jul 16, 2019 · 1 comment

Comments

@sanderhahn
Copy link

This line doesn't seem to properly escapes single quotes using bash as a shell: https://github.com/fabric/patchwork/blob/master/patchwork/files.py#L130, possibly because bash needs a $'...\'...' (https://wiki.bash-hackers.org/scripting/bashchanges#quoting_expansions_substitutions_and_related).

patchwork.files.append(c, filename="/etc/postgresql/10/main/postgresql.conf", text="listen_addresses = '*'", escape=True)
# line that is added:
# listen_addresses = \*\\

This script shows the problem that i am experiencing:

import subprocess

def run(script):
    process = subprocess.run(
        ["bash", "-s"], capture_output=True, input=script.encode("ascii"))
    stderr = process.stderr.decode("ascii")
    print(stderr, end="")
    stdout = process.stdout.decode("ascii")
    print(stdout, end="")

line = "listen_addresses = '*'"

escaped = line.replace("'", r"'\\''")
script = f"echo '{escaped}'"
run(script)
# listen_addresses = \*\\

line = "listen_addresses = '*'"
escaped = "$'" + line.replace("'", r"\'") + "'"
script = f"echo {escaped}"
run(script)
# listen_addresses = '*'

Thank you for Fabric! :)

@sanderhahn
Copy link
Author

shlex.quote can also quote shell arguments: https://docs.python.org/3/library/shlex.html?highlight=shlex#shlex.quote

import shlex
print(shlex.quote("listen_addresses = '*'"))

nixon added a commit to nixon/patchwork that referenced this issue Oct 20, 2019
nixon added a commit to nixon/patchwork that referenced this issue Oct 20, 2019
revert back to fabric1 version of `_escape_for_regex` to handle single
quotes and other special characters.

also escaped double quotes in filename and added testcases.

refs fabric#34
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

1 participant