From b3e593c1ba1ecf499a8db7f6a59e31868fcd1556 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Fri, 27 Mar 2020 17:16:34 +0000 Subject: [PATCH] Escape AST string before writing to tokens This patch enables more unit tests on Windows. R=ehmaldonado@chromium.org Change-Id: I8667777fc6eef11568aa2aead9850f7e37757e58 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2123808 Reviewed-by: Edward Lesmes Commit-Queue: Josip Sokcevic --- gclient_eval.py | 14 ++++++++------ tests/gclient_eval_unittest.py | 13 +++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/gclient_eval.py b/gclient_eval.py index f682d354c..f546a6679 100644 --- a/gclient_eval.py +++ b/gclient_eval.py @@ -605,6 +605,7 @@ def _UpdateAstString(tokens, node, value): quote_char = '' if isinstance(node, ast.Str): quote_char = tokens[position][1][0] + value = value.encode('unicode_escape').decode('utf-8') tokens[position][1] = quote_char + value + quote_char node.s = value @@ -759,12 +760,13 @@ def SetRevision(gclient_dict, dep_name, new_revision): if isinstance(node, ast.BinOp): node = node.right - token = tokens[node.lineno, node.col_offset][1][1:-1] - if isinstance(node, ast.Str) and token != node.s: - raise ValueError( - 'Can\'t update value for %s. Multiline strings and implicitly ' - 'concatenated strings are not supported.\n' - 'Consider reformatting the DEPS file.' % dep_key) + if isinstance(node, ast.Str): + token = _gclient_eval(tokens[node.lineno, node.col_offset][1]) + if token != node.s: + raise ValueError( + 'Can\'t update value for %s. Multiline strings and implicitly ' + 'concatenated strings are not supported.\n' + 'Consider reformatting the DEPS file.' % dep_key) if not isinstance(node, ast.Call) and not isinstance(node, ast.Str): diff --git a/tests/gclient_eval_unittest.py b/tests/gclient_eval_unittest.py index a4d38d88b..7f3b8a2f6 100755 --- a/tests/gclient_eval_unittest.py +++ b/tests/gclient_eval_unittest.py @@ -663,6 +663,19 @@ class RevisionTest(unittest.TestCase): ] self.assert_gets_and_sets_revision(before, after) + def test_revision_windows_local_path(self): + before = [ + 'deps = {', + ' "src/dep": "file:///C:\\\\path.git@deadbeef",', + '}', + ] + after = [ + 'deps = {', + ' "src/dep": "file:///C:\\\\path.git@deadfeed",', + '}', + ] + self.assert_gets_and_sets_revision(before, after) + def test_revision_multiline_strings(self): deps = [ 'deps = {',