Bug 1499511 - [mozdevice] Support single-quotes in adb command line, r=gbrown.
authorBob Clary <bclary@bclary.com>
Wed, 17 Oct 2018 06:53:29 -0700
changeset 497457 02d89c011037d8407576ec58e307f632a8f64b0f
parent 497415 a729ef8fab784e20eeccececa5e69cc5dc153c09
child 497458 4c944453210c428f505bc2d81b3b7f1c99a262a6
child 497488 a64b17b18dae852bae1de933d840b823f8f1b643
push id9996
push userarchaeopteryx@coole-files.de
push dateThu, 18 Oct 2018 18:37:15 +0000
treeherdermozilla-beta@8efe26839243 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs1499511
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1499511 - [mozdevice] Support single-quotes in adb command line, r=gbrown.
testing/mozbase/mozdevice/mozdevice/adb.py
--- a/testing/mozbase/mozdevice/mozdevice/adb.py
+++ b/testing/mozbase/mozdevice/mozdevice/adb.py
@@ -764,28 +764,29 @@ class ADBDevice(ADBCommand):
             except ADBError:
                 self._logger.debug("Check for root adbd failed")
 
     @staticmethod
     def _escape_command_line(cmd):
         """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)
 
         return " ".join(quoted_cmd)
 
     @staticmethod
     def _get_exitcode(file_obj):
         """Get the exitcode from the last line of the file_obj for shell