mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
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 <ehmaldonado@chromium.org> Commit-Queue: Josip Sokcevic <sokcevic@google.com>
This commit is contained in:
@@ -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 = {',
|
||||
|
||||
Reference in New Issue
Block a user