On Thu, Jan 25, 2024 at 08:33:42 -0800, Andrea Bolognani wrote:
> On Tue, Jan 16, 2024 at 05:12:35PM +0100, Peter Krempa wrote:
> > diff --git a/tests/qemucapabilitiesnumbering.c 
> > b/tests/qemucapabilitiesnumbering.c
> > index 6f33321e17..2aabdf72c7 100644
> > --- a/tests/qemucapabilitiesnumbering.c
> > +++ b/tests/qemucapabilitiesnumbering.c
> > @@ -137,10 +137,32 @@ printLineSkipEmpty(const char *p,
> >                     virBuffer *buf)
> >  {
> >      for (; *p; p++) {
> > -        if (p[0] == '\n' && p[1] == '\n')
> > -            continue;
> > -
> >          virBufferAddChar(buf, *p);
> > +
> > +        /* YAJL formats empty objects and arrays in a weird way:
> > +         *
> > +         * {
> > +         *   "emptyarray": [
> > +         *
> > +         *   ],
> > +         *   "emptyobject": {
> > +         *
> > +         *   }
> > +         * }
> > +         *
> > +         * We want to use empty lines to separate commands and replies as
> > +         * well as be compatible with python's 'json.dump' method, thus we 
> > drop
> > +         * any whitespace between array/object braces.
> > +         */
> > +        if ((p[0] == '{' || p[0] == '[') && p[1] == '\n') {
> 
> I think you can lose the check on p[1]: whenever there's an opening
> token, we can just skip all whitespace, including the initial
> newline.

JSON allows un-escaped '{' '[' inside a string:

$ jq <<< '{"blah":"[{"}'
{
  "blah": "[{"
}

And even if it were escaped it's escaped with the traditional backslash
sequence e.g. '\"', thus the very easy state machine above would still
consider it.

TBH I didn't check if it's present in our data though.

> 
> Either way,
> 
>   Reviewed-by: Andrea Bolognani <abolo...@redhat.com>
> 
> -- 
> Andrea Bolognani / Red Hat / Virtualization
> 
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-le...@lists.libvirt.org

Reply via email to