diff mbox series

[v4,2/7] test-keyval: Demonstrate misparse of ', ' with implied key

Message ID 20201011073505.1185335-3-armbru@redhat.com
State New
Headers show
Series qemu-storage-daemon: Remove QemuOpts from --object | expand

Commit Message

Markus Armbruster Oct. 11, 2020, 7:35 a.m. UTC
Add a test for "val,,ue" with implied key.  Documentation says this
should parse as implied key with value "val", then fail.  The code
parses it as implied key with value "val,ue", then succeeds.  The next
commit will fix it.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 tests/test-keyval.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Eric Blake Oct. 12, 2020, 11:44 a.m. UTC | #1
On 10/11/20 2:35 AM, Markus Armbruster wrote:
> Add a test for "val,,ue" with implied key.  Documentation says this

> should parse as implied key with value "val", then fail.  The code

> parses it as implied key with value "val,ue", then succeeds.  The next

> commit will fix it.

> 

> Signed-off-by: Markus Armbruster <armbru@redhat.com>

> ---

>   tests/test-keyval.c | 7 +++++++

>   1 file changed, 7 insertions(+)


Reviewed-by: Eric Blake <eblake@redhat.com>


> 

> diff --git a/tests/test-keyval.c b/tests/test-keyval.c

> index e331a84149..f02bdf7029 100644

> --- a/tests/test-keyval.c

> +++ b/tests/test-keyval.c

> @@ -182,6 +182,13 @@ static void test_keyval_parse(void)

>       error_free_or_abort(&err);

>       g_assert(!qdict);

>   

> +    /* Implied key's value can't have comma (qemu_opts_parse(): it can) */

> +    /* BUG: it can */

> +    qdict = keyval_parse("val,,ue", "implied", &error_abort);

> +    g_assert_cmpuint(qdict_size(qdict), ==, 1);

> +    g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), ==, "val,ue");

> +    qobject_unref(qdict);

> +

>       /* Empty key is not an implied key */

>       qdict = keyval_parse("=val", "implied", &err);

>       error_free_or_abort(&err);

> 


-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
diff mbox series

Patch

diff --git a/tests/test-keyval.c b/tests/test-keyval.c
index e331a84149..f02bdf7029 100644
--- a/tests/test-keyval.c
+++ b/tests/test-keyval.c
@@ -182,6 +182,13 @@  static void test_keyval_parse(void)
     error_free_or_abort(&err);
     g_assert(!qdict);
 
+    /* Implied key's value can't have comma (qemu_opts_parse(): it can) */
+    /* BUG: it can */
+    qdict = keyval_parse("val,,ue", "implied", &error_abort);
+    g_assert_cmpuint(qdict_size(qdict), ==, 1);
+    g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), ==, "val,ue");
+    qobject_unref(qdict);
+
     /* Empty key is not an implied key */
     qdict = keyval_parse("=val", "implied", &err);
     error_free_or_abort(&err);