Skip to content

single quotes not properly escaped #34

@sanderhahn

Description

@sanderhahn

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! :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions