Bug 1499511 - [mozdevice] Support single-quotes in adb command line, r=gbrown.

This commit is contained in:
Bob Clary 2018-10-17 06:53:29 -07:00
parent b2cb203c15
commit 26b400b059

View File

@ -769,18 +769,19 @@ class ADBDevice(ADBCommand):
"""Utility function to return escaped and quoted version of command
line.
"""
re_quotable_chars = re.compile(r"[ ()\"&'\]]")
def is_quoted(s, delim):
if not s:
return False
return s[0] == delim and s[-1] == delim
quoted_cmd = []
for arg in cmd:
arg.replace('&', r'\&')
needs_quoting = False
for char in [' ', '(', ')', '"', '&']:
if arg.find(char) >= 0:
needs_quoting = True
break
if needs_quoting:
arg = "'%s'" % arg
if not is_quoted(arg, "'") and not is_quoted(arg, '"') and \
re_quotable_chars.search(arg):
arg = '"%s"' % arg.replace(r'"', r'\"')
quoted_cmd.append(arg)