util: qemu: Add support for user-passed strings in JSON->commandline

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.
This commit is contained in:
Peter Krempa 2016-07-25 14:37:47 +02:00
parent f0276c3489
commit 25a272ada4
2 changed files with 3 additions and 1 deletions

View File

@ -46,7 +46,8 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,
switch ((virJSONType) value->type) { switch ((virJSONType) value->type) {
case VIR_JSON_TYPE_STRING: case VIR_JSON_TYPE_STRING:
virBufferAsprintf(buf, ",%s=%s", key, value->data.string); virBufferAsprintf(buf, ",%s=", key);
virQEMUBuildBufferEscapeComma(buf, value->data.string);
break; break;
case VIR_JSON_TYPE_NUMBER: case VIR_JSON_TYPE_NUMBER:

View File

@ -100,6 +100,7 @@ mymain(void)
DO_TEST_COMMAND_OBJECT_FROM_JSON("{}", NULL); DO_TEST_COMMAND_OBJECT_FROM_JSON("{}", NULL);
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"string\":\"qwer\"}", "string=qwer"); 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("{\"number\":1234}", "number=1234");
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":true}", "boolean=yes"); DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":true}", "boolean=yes");
DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":false}", "boolean=no"); DO_TEST_COMMAND_OBJECT_FROM_JSON("{\"boolean\":false}", "boolean=no");