Bug 1452483 - Strip whitespace from injected scripts. r?maja_zf draft
authorAndreas Tolfsen <ato@sny.no>
Mon, 09 Apr 2018 11:41:46 +0100
changeset 780425 d3194be79b21cf1251ecb0af4f7b6e08640bfa34
parent 780424 bcb03dbd162888273a969342aae0fd375750b441
child 780426 dc94597876c49f2e7725e0ec0d98cbed159ed056
push id105996
push userbmo:ato@sny.no
push dateWed, 11 Apr 2018 12:15:00 +0000
reviewersmaja_zf
bugs1452483
milestone61.0a1
Bug 1452483 - Strip whitespace from injected scripts. r?maja_zf The injected script may contain a lot of whitespace padding on either side of the string when using multi-line strings ("""foo""") in Python. To improve readability of the trace log we can strip it off before sending it to Marionette. MozReview-Commit-ID: 2cNlwVzqWTK
testing/marionette/client/marionette_driver/marionette.py
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -1701,17 +1701,17 @@ class Marionette(object):
             marionette.execute_script("global.test1 = 'foo';")
             result = self.marionette.execute_script("return global.test1;", new_sandbox=False)
             assert result == "foo"
 
         """
         args = self._to_json(script_args)
         stack = traceback.extract_stack()
         frame = stack[-2:-1][0]  # grab the second-to-last frame
-        body = {"script": script,
+        body = {"script": script.strip(),
                 "args": args,
                 "newSandbox": new_sandbox,
                 "sandbox": sandbox,
                 "scriptTimeout": script_timeout,
                 "line": int(frame[1]),
                 "filename": os.path.basename(frame[0])}
 
         rv = self._send_message("WebDriver:ExecuteScript",
@@ -1751,17 +1751,17 @@ class Marionette(object):
                 marionetteScriptFinished(1);
               }, 5000);
             ''')
             assert result == 1
         """
         args = self._to_json(script_args)
         stack = traceback.extract_stack()
         frame = stack[-2:-1][0]  # grab the second-to-last frame
-        body = {"script": script,
+        body = {"script": script.strip(),
                 "args": args,
                 "newSandbox": new_sandbox,
                 "sandbox": sandbox,
                 "scriptTimeout": script_timeout,
                 "line": int(frame[1]),
                 "filename": os.path.basename(frame[0]),
                 "debug_script": debug_script}