]> git.ipfire.org Git - thirdparty/qemu.git/commit
qmp-shell: fix nested json regression
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Tue, 5 Feb 2019 13:49:26 +0000 (14:49 +0100)
committerEduardo Habkost <ehabkost@redhat.com>
Mon, 11 Mar 2019 13:22:31 +0000 (10:22 -0300)
commitb35203b227261961ff1da9b77b546c1919968bee
tree21135476a454c61542512b87e1ef1b6dabc5d9f9
parent336cfef495f0cd5b1606251c52628d0372e9a809
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>
scripts/qmp/qmp-shell