[PATCH 14/25] util: qemu: Add support for user-passed strings in JSON->commandline

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Until now the JSON->commandline convertor was used only for objects
created by qemu. To allow reusing it with disk formatter we'll need to
escape ',' as usual in qemu commandlines.
---
 src/util/virqemu.c          | 3 ++-
 tests/qemucommandutiltest.c | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/util/virqemu.c b/src/util/virqemu.c
index a5d5385..99c14c2 100644
--- a/src/util/virqemu.c
+++ b/src/util/virqemu.c
@@ -46,7 +46,8 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,

     switch ((virJSONType) value->type) {
     case VIR_JSON_TYPE_STRING:
-        virBufferAsprintf(buf, ",%s=%s", key, value->data.string);
+        virBufferAsprintf(buf, ",%s=", key);
+        virQEMUBuildBufferEscapeComma(buf, value->data.string);
         break;

     case VIR_JSON_TYPE_NUMBER:
diff --git a/tests/qemucommandutiltest.c b/tests/qemucommandutiltest.c
index 21fef1c..8299462 100644
--- a/tests/qemucommandutiltest.c
+++ b/tests/qemucommandutiltest.c
@@ -100,6 +100,7 @@ mymain(void)

     DO_TEST_COMMAND_OBJECT_FROM_JSON("{}", NULL);
     DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"string\":\"qwer\"}", "string=qwer");
+    DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"string\":\"qw,e,r\"}", "string=qw,,e,,r");
     DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"number\":1234}", "number=1234");
     DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":true}", "boolean=yes");
     DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":false}", "boolean=no");
-- 
2.9.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]