Re: [PATCH 01/10] tests: qemucaps: Make JSON output identical to python's 'json.dump' method

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

 



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 <abologna@xxxxxxxxxx>
> 
> -- 
> Andrea Bolognani / Red Hat / Virtualization
> 
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[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]

  Powered by Linux