Skip to content

Commit

Permalink
Fix bug in counting backspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
JordonPhillips committed Jun 30, 2017
1 parent b4946de commit 17657c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion awscli/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,12 @@ def _windows_shell_quote(s):
# they will need to be escaped. Instead we separately keep track
# of how many we've seen.
num_backspaces += 1
if character == '"':
elif character == '"':
if num_backspaces > 0:
# The backslashes are part of a chain that lead up to a
# double quote, so they need to be escaped.
buff.append('\\' * (num_backspaces * 2))
num_backspaces = 0

# The double quote also needs to be escaped. The fact that we're
# seeing it at all means that it must have been escaped in the
Expand All @@ -245,6 +246,11 @@ def _windows_shell_quote(s):
num_backspaces = 0
buff.append(character)

# There may be some leftover backspaces if they were on the trailing
# end, so they're added back in here.
if num_backspaces > 0:
buff.append('\\' * num_backspaces)

new_s = ''.join(buff)
if ' ' in new_s or '\t' in new_s:
# If there are any spaces or tabs then the string needs to be double
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def test_compat_shell_quote_windows():
windows_cases = {
'': '""',
'"': '\\"',
'\\': '\\\\',
'\\': '\\',
'\\a': '\\a',
'\\\\': '\\\\',
'\\"': '\\\\\\"',
'\\\\"': '\\\\\\\\\\"',
'foo bar': '"foo bar"',
Expand Down

0 comments on commit 17657c4

Please sign in to comment.