diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2019-02-05 14:49:26 +0100 |
---|---|---|
committer | Eduardo Habkost <ehabkost@redhat.com> | 2019-03-11 10:22:31 -0300 |
commit | b35203b227261961ff1da9b77b546c1919968bee (patch) | |
tree | 21135476a454c61542512b87e1ef1b6dabc5d9f9 /scripts | |
parent | 336cfef495f0cd5b1606251c52628d0372e9a809 (diff) | |
download | qemu-b35203b227261961ff1da9b77b546c1919968bee.zip qemu-b35203b227261961ff1da9b77b546c1919968bee.tar.gz qemu-b35203b227261961ff1da9b77b546c1919968bee.tar.bz2 |
qmp-shell: fix nested json regression
Commit fcfab7541 ("qmp-shell: learn to send commands with quoted
arguments") introduces the usage of Python 'shlex' to handle quoted
arguments, but it accidentally broke generation of nested JSON
structs.
shlex drops quotes, which breaks parsing of the nested struct.
cmd='blockdev-create job-id="job0 foo" options={"driver":"qcow2","size":16384,"file":{"driver":"file","filename":"foo.qcow2"}}'
shlex.split(cmd)
['blockdev-create',
'job-id=job0 foo',
'options={driver:qcow2,size:16384,file:{driver:file,filename:foo.qcow2}}']
Replace with a regexp to split while respecting quoted strings and preserving quotes:
re.findall(r'''(?:[^\s"']|"(?:\\.|[^"])*"|'(?:\\.|[^'])*')+''', cmd)
['blockdev-create',
'job-id="job0 foo"',
'options={"driver":"qcow2","size":16384,"file":{"driver":"file","filename":"foo.qcow2"}}']
Fixes: fcfab7541 ("qmp-shell: learn to send commands with quoted arguments")
Reported-by: Kashyap Chamarthy <kchamart@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20190205134926.8312-1-marcandre.lureau@redhat.com>
Tested-by: Kashyap Chamarthy <kchamart@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/qmp/qmp-shell | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 9fec46e..7776c7b 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -73,7 +73,7 @@ import sys import os import errno import atexit -import shlex +import re sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python')) from qemu import qmp @@ -222,7 +222,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): < command-name > [ arg-name1=arg1 ] ... [ arg-nameN=argN ] """ - cmdargs = shlex.split(cmdline) + cmdargs = re.findall(r'''(?:[^\s"']|"(?:\\.|[^"])*"|'(?:\\.|[^'])*')+''', cmdline) # Transactional CLI entry/exit: if cmdargs[0] == 'transaction(': |