Commit b3e593c1 authored by Josip Sokcevic's avatar Josip Sokcevic Committed by LUCI CQ

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/+/2123808Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
parent 6cf3d249
......@@ -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):
......
......@@ -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 = {',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment