summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitreview2
-rw-r--r--cliff/formatters/shell.py3
-rw-r--r--cliff/tests/test_formatters_shell.py20
3 files changed, 23 insertions, 2 deletions
diff --git a/.gitreview b/.gitreview
index 212f062..0207650 100644
--- a/.gitreview
+++ b/.gitreview
@@ -1,4 +1,4 @@
[gerrit]
host=review.openstack.org
port=29418
-project=stackforge/cliff.git
+project=openstack/cliff.git
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
new file mode 100644
index 0000000..93452ba
--- /dev/null
+++ b/cliff/tests/test_formatters_shell.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+from six import StringIO
+
+from cliff.formatters import shell
+
+import mock
+
+
+def test_shell_formatter():
+ sf = shell.ShellFormatter()
+ 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', 'd']
+ args.prefix = ''
+ sf.emit_one(c, d, output, args)
+ actual = output.getvalue()
+ assert expected == actual