xemu/scripts/qmp
Marc-André Lureau b35203b227 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>
2019-03-11 10:22:31 -03:00
..
qemu-ga-client Introduce a Python module structure 2019-02-22 14:07:01 -05:00
qmp Partially revert "python: futurize -f libfuturize.fixes.fix_absolute_import" 2018-06-22 15:45:42 -03:00
qmp-shell qmp-shell: fix nested json regression 2019-03-11 10:22:31 -03:00
qom-fuse Partially revert "python: futurize -f libfuturize.fixes.fix_absolute_import" 2018-06-22 15:45:42 -03:00
qom-get Partially revert "python: futurize -f libfuturize.fixes.fix_absolute_import" 2018-06-22 15:45:42 -03:00
qom-list Partially revert "python: futurize -f libfuturize.fixes.fix_absolute_import" 2018-06-22 15:45:42 -03:00
qom-set Partially revert "python: futurize -f libfuturize.fixes.fix_absolute_import" 2018-06-22 15:45:42 -03:00
qom-tree Partially revert "python: futurize -f libfuturize.fixes.fix_absolute_import" 2018-06-22 15:45:42 -03:00