Clarify std/json quirk_allow_backslash_x semantics

This commit is contained in:
Nigel Tao committed 2020-04-08 11:08:01 +10:00
1 parent d83bd8d036
commit df3acfbb21
2 files changed
+15 -3

No files matched your search

+4
View File
@@ -624,6 +624,10 @@ JsonThing::parse_string(TokenStream& ts, TokenStream::Result tsr) {
// program doesn't enable that by default, but if you're copy/pasting
// this JsonThing code and your program does enable that option,
// here's how to handle it.
//
// As per the quirk documentation, there are two options for how to
// interpret a backslash-x: as a byte or as a Unicode code point.
// This implementation chooses as a byte.
wuffs_base__slice_u8 encoded = tsr.src_data;
if (encoded.len & 3) {
return Result(
+11 -3
View File
@@ -75,14 +75,22 @@ pub const quirk_allow_backslash_single_quote base.u32 = 0x4909_9400 | 0x06
pub const quirk_allow_backslash_v base.u32 = 0x4909_9400 | 0x07
// When this quirk is enabled, e.g. "abc\xeFz" is accepted as a JSON string,
// decoding to 5 bytes: 0x61, 0x62, 0x63, 0xEF and 0x7A. There are exactly 2
// encoded bytes after each "\x".
// There are exactly 2 encoded bytes after each "\x".
//
// "\x", "\x9", "\x9$" and "\X99" are all still rejected.
//
// It is up to the caller how to interpret the two hexadecimal digits. There
// are two sensible choices: as a byte or as a Unicode code point.
//
// As a byte means decoding to 5 bytes: 0x61, 0x62, 0x63, 0xEF and 0x7A.
// Decoded strings are byte strings, no longer guaranteed to be valid UTF-8 and
// even if the overall byte string is valid UTF-8, tokens are also no longer
// guaranteed to split on UTF-8 boundaries.
//
// "\x", "\x9", "\x9$" and "\X99" are all still rejected.
// As a Unicode code point means decoding to 6 bytes: 0x61, 0x62, 0x63, 0xC3,
// 0xAF and 0x7A. The UTF-8 encoding of U+00EF LATIN SMALL LETTER I WITH
// DIAERESIS is the two byte sequence (0xC3, 0xAF). Decoded strings are still
// valid UTF-8 and tokens still split on UTF-8 boundaries.
pub const quirk_allow_backslash_x base.u32 = 0x4909_9400 | 0x08
// When this quirk is enabled, e.g. "abc\0z" is accepted as a JSON string,