Skip to contentSkip to conversation

qmp-shell: fix nested json regression

GIT PULL Eduardo Habkost 1 participant 2 messages Mar 12, 2019

lore
Share & tools
lore
#0 lore raw

The following changes since commit 336cfef495f0cd5b1606251c52628d0372e9a809:

Makefile: Don't install non-sphinx files in sphinx docs install (2019-03-11 11:10:44 +0000)

are available in the Git repository at:

git://github.com/ehabkost/qemu.git tags/python-next-pull-request

for you to fetch changes up to b35203b227261961ff1da9b77b546c1919968bee:

qmp-shell: fix nested json regression (2019-03-11 10:22:31 -0300)

----------------------------------------------------------------
qmp-shell: fix nested json regression

One small bug fix.

----------------------------------------------------------------

Marc-André Lureau (1):
qmp-shell: fix nested json regression

 scripts/qmp/qmp-shell | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
#1 lore raw

From: Marc-André Lureau <[email protected]>

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")

Message-Id: <[email protected]>

---
 scripts/qmp/qmp-shell | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/qmp/qmp-shell +2 -2
index 9fec46e2ed..7776c7b141 100755
@@ -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(':
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140