diff options
-rw-r--r-- | cliff/formatters/shell.py | 3 | ||||
-rw-r--r-- | cliff/tests/test_formatters_shell.py | 8 |
2 files changed, 6 insertions, 5 deletions
diff --git a/cliff/formatters/shell.py b/cliff/formatters/shell.py index d1c392b..385d48c 100644 --- a/cliff/formatters/shell.py +++ b/cliff/formatters/shell.py @@ -34,5 +34,6 @@ class ShellFormatter(SingleFormatter): desired_columns = parsed_args.variables for name, value in zip(variable_names, data): if name in desired_columns or not desired_columns: - stdout.write('%s%s="%s"\n' % (parsed_args.prefix, name, value)) + stdout.write('%s%s="%s"\n' % (parsed_args.prefix, name, + value.replace('"', '\\"'))) return diff --git a/cliff/tests/test_formatters_shell.py b/cliff/tests/test_formatters_shell.py index 5d49e65..93452ba 100644 --- a/cliff/tests/test_formatters_shell.py +++ b/cliff/tests/test_formatters_shell.py @@ -8,12 +8,12 @@ import mock def test_shell_formatter(): sf = shell.ShellFormatter() - c = ('a', 'b', 'c') - d = ('A', 'B', 'C') - expected = 'a="A"\nb="B"\n' + c = ('a', 'b', 'c', 'd') + d = ('A', 'B', 'C', '"escape me"') + expected = 'a="A"\nb="B"\nd="\\"escape me\\""\n' output = StringIO() args = mock.Mock() - args.variables = ['a', 'b'] + args.variables = ['a', 'b', 'd'] args.prefix = '' sf.emit_one(c, d, output, args) actual = output.getvalue() |