qapi: Support (subset of) \u escapes in strings
commita7f5966b297330f6492020019544ae87c45d699b
authorEric Blake <eblake@redhat.com>
Mon, 4 May 2015 15:05:36 +0000 (4 09:05 -0600)
committerMarkus Armbruster <armbru@redhat.com>
Tue, 5 May 2015 16:39:02 +0000 (5 18:39 +0200)
tree45224ce83f62a85570c12dfcd09ae22293b06123
parent363b4262a10a52f6d7ac1073bab5e6648da4051b
qapi: Support (subset of) \u escapes in strings

The handling of \ inside QAPI strings was less than ideal, and
really only worked JSON's \/, \\, \", and our extension of \'
(an obvious extension, when you realize we use '' instead of ""
for strings).  For other things, like '\n', it resulted in a
literal 'n' instead of a newline.

Of course, at the moment, we really have no use for escaped
characters, as QAPI has to map to C identifiers, and we currently
support ASCII only for that.  But down the road, we may add
support for default values for string parameters to a command
or struct; if that happens, it would be nice to correctly support
all JSON escape sequences, such as \n or \uXXXX.  This gets us
closer, by supporting Unicode escapes in the ASCII range.

Since JSON does not require \OCTAL or \xXX escapes, and our QMP
implementation does not understand them either, I intentionally
reject it here, but it would be an easy addition if we desired it.
Likewise, intentionally refusing the NUL byte means we don't have
to worry about C strings being shorter than the qapi input.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
26 files changed:
scripts/qapi.py
tests/Makefile
tests/qapi-schema/escape-outside-string.err [new file with mode: 0644]
tests/qapi-schema/escape-outside-string.exit [copied from tests/qapi-schema/ident-with-escape.exit with 100% similarity]
tests/qapi-schema/escape-outside-string.json [new file with mode: 0644]
tests/qapi-schema/escape-outside-string.out [copied from tests/qapi-schema/ident-with-escape.out with 100% similarity]
tests/qapi-schema/escape-too-big.err [new file with mode: 0644]
tests/qapi-schema/escape-too-big.exit [copied from tests/qapi-schema/ident-with-escape.exit with 100% similarity]
tests/qapi-schema/escape-too-big.json [new file with mode: 0644]
tests/qapi-schema/escape-too-big.out [copied from tests/qapi-schema/ident-with-escape.out with 100% similarity]
tests/qapi-schema/escape-too-short.err [new file with mode: 0644]
tests/qapi-schema/escape-too-short.exit [copied from tests/qapi-schema/ident-with-escape.exit with 100% similarity]
tests/qapi-schema/escape-too-short.json [new file with mode: 0644]
tests/qapi-schema/escape-too-short.out [copied from tests/qapi-schema/ident-with-escape.out with 100% similarity]
tests/qapi-schema/ident-with-escape.err
tests/qapi-schema/ident-with-escape.exit
tests/qapi-schema/ident-with-escape.json
tests/qapi-schema/ident-with-escape.out
tests/qapi-schema/unicode-str.err [new file with mode: 0644]
tests/qapi-schema/unicode-str.exit [copied from tests/qapi-schema/ident-with-escape.exit with 100% similarity]
tests/qapi-schema/unicode-str.json [new file with mode: 0644]
tests/qapi-schema/unicode-str.out [copied from tests/qapi-schema/ident-with-escape.out with 100% similarity]
tests/qapi-schema/unknown-escape.err [new file with mode: 0644]
tests/qapi-schema/unknown-escape.exit [copied from tests/qapi-schema/ident-with-escape.exit with 100% similarity]
tests/qapi-schema/unknown-escape.json [new file with mode: 0644]
tests/qapi-schema/unknown-escape.out [copied from tests/qapi-schema/ident-with-escape.out with 100% similarity]