Skip to content

Commit

Permalink
Use a dictionary to store escaped characters and their
Browse files Browse the repository at this point in the history
corresponding escape forms. If you need to add new escape
characters later, just add them to the dictionary

Signed-off-by: changxuqing <[email protected]>
  • Loading branch information
changxuqing committed Jun 25, 2024
1 parent 679d622 commit 478126b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions avocado/utils/astring.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ def shell_escape(command):
See also: http://www.tldp.org/LDP/abs/html/escapingsection.html
"""
command = command.replace("\\", "\\\\")
command = command.replace("$", r"\$")
command = command.replace('"', r"\"")
command = command.replace("`", r"\`")
escape_chars = {
"\\": "\\\\",
"$": r"\$",
'"': r'\"',
"`": r"\`"
}
for char, escaped_char in escape_chars.items():
command = command.replace(char, escaped_char)
return command


Expand Down

0 comments on commit 478126b

Please sign in to comment.