qemu-e2k/qobject
Markus Armbruster b2da4a4d75 json: Leave rejecting invalid escape sequences to parser
Both lexer and parser reject invalid escape sequences in strings.  The
parser's check is useless.

The lexer ends the token right after the first non-well-formed byte.
This tends to lead to suboptimal error reporting.  For instance, input

    {"abc\@ijk": 1}

produces the tokens

    JSON_LCURLY   {
    JSON_ERROR    "abc\@
    JSON_KEYWORD  ijk
    JSON_ERROR   ": 1}\n

The parser then reports three errors

    Invalid JSON syntax
    JSON parse error, invalid keyword 'ijk'
    Invalid JSON syntax

before it recovers at the newline.

Drop the lexer's escape sequence checking, and make it accept the same
characters after backslash it accepts elsewhere in strings.  It now
produces

    JSON_LCURLY   {
    JSON_STRING   "abc\@ijk"
    JSON_COLON    :
    JSON_INTEGER  1
    JSON_RCURLY

and the parser reports just

    JSON parse error, invalid escape sequence in string

While there, fix parse_string()'s inaccurate function comment.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180823164025.12553-27-armbru@redhat.com>
2018-08-24 20:26:37 +02:00
..
Makefile.objs qobject: Move block-specific qdict code to block-qdict.c 2018-06-15 14:49:44 +02:00
block-qdict.c qdict: Make qdict_extract_subqdict() accept dst = NULL 2018-08-15 12:50:39 +02:00
json-lexer.c json: Leave rejecting invalid escape sequences to parser 2018-08-24 20:26:37 +02:00
json-parser.c json: Leave rejecting invalid escape sequences to parser 2018-08-24 20:26:37 +02:00
json-streamer.c json-streamer: fix double-free on exiting during a parse 2016-07-12 18:31:27 +02:00
qbool.c qapi: Remove qobject_to_X() functions 2018-03-19 14:58:36 -05:00
qdict.c qobject: Move block-specific qdict code to block-qdict.c 2018-06-15 14:49:44 +02:00
qjson.c qobject: qobject_from_jsonv() is dangerous, hide it away 2018-08-16 08:42:06 +02:00
qlist.c qobject: Replace qobject_incref/QINCREF qobject_decref/QDECREF 2018-05-04 08:27:53 +02:00
qlit.c qapi: Replace qobject_to_X(o) by qobject_to(X, o) 2018-03-19 14:58:36 -05:00
qnull.c qapi: Add qobject_is_equal() 2017-11-17 18:21:30 +01:00
qnum.c qapi: Remove qobject_to_X() functions 2018-03-19 14:58:36 -05:00
qobject.c qobject: use a QObjectBase_ struct 2018-05-04 08:27:53 +02:00
qstring.c qstring: Move qstring_from_substr()'s @end one to the right 2018-07-28 09:09:58 +02:00