mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-21 16:47:28 +01:00
Drop WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_X_AS_BYTES
We can always add it back later if there's demand for it.
This commit is contained in:
1 parent
6bc3f5716d
commit
6c13877688
9 files changed
+250
-522
No files matched your search
+60
-104
@@ -20,8 +20,6 @@ pub struct decoder? implements base.token_decoder(
|
||||
|
||||
end_of_data : base.bool,
|
||||
|
||||
string_value_minor : base.u32[..= 0x1FF_FFFF],
|
||||
|
||||
util : base.utility,
|
||||
)(
|
||||
// stack is conceptually an array of bits, implemented as an array of u32.
|
||||
@@ -92,7 +90,6 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
var class : base.u8[..= 0x0F]
|
||||
var multi_byte_utf8 : base.u32
|
||||
|
||||
var backslash_x_length : base.u32[..= 0xFFFF]
|
||||
var backslash_x_ok : base.u8
|
||||
var backslash_x_value : base.u8
|
||||
var backslash_x_string : base.u32
|
||||
@@ -124,16 +121,6 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
this.decode_leading?(dst: args.dst, src: args.src)
|
||||
}
|
||||
|
||||
if this.quirks[QUIRK_ALLOW_BACKSLASH_X_AS_BYTES - QUIRKS_BASE] {
|
||||
if this.quirks[QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS - QUIRKS_BASE] {
|
||||
return "#bad quirk combination"
|
||||
}
|
||||
this.string_value_minor = (base.TOKEN__VBC__STRING << 21)
|
||||
} else {
|
||||
this.string_value_minor = (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8
|
||||
}
|
||||
|
||||
expect = EXPECT_VALUE
|
||||
|
||||
while.outer true {
|
||||
@@ -217,8 +204,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
// Emit the leading '"'.
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: this.string_value_minor |
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_ASCII |
|
||||
base.TOKEN__VBD__STRING__CONVERT_0_DST_1_SRC_DROP,
|
||||
continued: 1,
|
||||
@@ -239,8 +227,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
if string_length > 0 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: this.string_value_minor |
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY,
|
||||
continued: 1,
|
||||
length: string_length)
|
||||
@@ -271,8 +260,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
if string_length > (0xFFFB - 4) {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: this.string_value_minor |
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY,
|
||||
continued: 1,
|
||||
length: string_length + 4)
|
||||
@@ -290,8 +280,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
if string_length >= 0xFFFB {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: this.string_value_minor |
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY,
|
||||
continued: 1,
|
||||
length: 0xFFFC)
|
||||
@@ -305,8 +296,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
if string_length <> 0 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: this.string_value_minor |
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY,
|
||||
continued: 1,
|
||||
length: string_length)
|
||||
@@ -318,8 +310,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
if string_length > 0 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: this.string_value_minor |
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY,
|
||||
continued: 1,
|
||||
length: string_length)
|
||||
@@ -566,88 +559,43 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
}
|
||||
// -------- END backslash-capital-u.
|
||||
|
||||
} else if (c == 'x') {
|
||||
} else if (c == 'x') and
|
||||
this.quirks[QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS - QUIRKS_BASE] {
|
||||
// -------- BEGIN backslash-x
|
||||
if this.quirks[QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS - QUIRKS_BASE] {
|
||||
if args.src.length() < 4 {
|
||||
if args.src.is_closed() {
|
||||
return "#bad backslash-escape"
|
||||
}
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
char = 0
|
||||
continue.string_loop_outer
|
||||
}
|
||||
|
||||
backslash_x_string = args.src.peek_u32le()
|
||||
backslash_x_ok = 0x80
|
||||
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (backslash_x_string >> 16)]
|
||||
backslash_x_ok &= c
|
||||
backslash_x_value = ((c & 0x0F) << 4) as base.u8
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (backslash_x_string >> 24)]
|
||||
backslash_x_ok &= c
|
||||
backslash_x_value = (backslash_x_value | (c & 0x0F)) as base.u8
|
||||
|
||||
if (backslash_x_ok == 0) or
|
||||
((backslash_x_string & 0xFFFF) <> 0x785C) {
|
||||
// It wasn't "\\x34", for some hexadecimal
|
||||
// digits "34".
|
||||
if args.src.length() < 4 {
|
||||
if args.src.is_closed() {
|
||||
return "#bad backslash-escape"
|
||||
}
|
||||
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__UNICODE_CODE_POINT << 21) |
|
||||
(backslash_x_value as base.u32),
|
||||
continued: 1,
|
||||
length: 4)
|
||||
continue.string_loop_outer
|
||||
} else if this.quirks[QUIRK_ALLOW_BACKSLASH_X_AS_BYTES - QUIRKS_BASE] {
|
||||
if args.src.length() < 4 {
|
||||
if args.src.is_closed() {
|
||||
return "#bad backslash-escape"
|
||||
}
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
char = 0
|
||||
continue.string_loop_outer
|
||||
}
|
||||
|
||||
backslash_x_length = 0
|
||||
while (backslash_x_length <= 0xFFFB) and (args.src.length() >= 4),
|
||||
inv args.dst.length() > 0,
|
||||
{
|
||||
backslash_x_string = args.src.peek_u32le()
|
||||
backslash_x_ok = 0x80
|
||||
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (backslash_x_string >> 16)]
|
||||
backslash_x_ok &= c
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (backslash_x_string >> 24)]
|
||||
backslash_x_ok &= c
|
||||
|
||||
if (backslash_x_ok == 0) or
|
||||
((backslash_x_string & 0xFFFF) <> 0x785C) {
|
||||
// It wasn't "\\x34", for some hexadecimal
|
||||
// digits "34".
|
||||
break
|
||||
}
|
||||
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
|
||||
backslash_x_length += 4
|
||||
} endwhile
|
||||
|
||||
if backslash_x_length == 0 {
|
||||
return "#bad backslash-escape"
|
||||
}
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: this.string_value_minor |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CONVERT_1_DST_4_SRC_BACKSLASH_X,
|
||||
continued: 1,
|
||||
length: backslash_x_length)
|
||||
yield? base."$short read"
|
||||
string_length = 0
|
||||
char = 0
|
||||
continue.string_loop_outer
|
||||
}
|
||||
|
||||
backslash_x_string = args.src.peek_u32le()
|
||||
backslash_x_ok = 0x80
|
||||
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (backslash_x_string >> 16)]
|
||||
backslash_x_ok &= c
|
||||
backslash_x_value = ((c & 0x0F) << 4) as base.u8
|
||||
c = LUT_HEXADECIMAL_DIGITS[0xFF & (backslash_x_string >> 24)]
|
||||
backslash_x_ok &= c
|
||||
backslash_x_value = (backslash_x_value | (c & 0x0F)) as base.u8
|
||||
|
||||
if (backslash_x_ok == 0) or
|
||||
((backslash_x_string & 0xFFFF) <> 0x785C) {
|
||||
// It wasn't "\\x34", for some hexadecimal
|
||||
// digits "34".
|
||||
return "#bad backslash-escape"
|
||||
}
|
||||
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__UNICODE_CODE_POINT << 21) |
|
||||
(backslash_x_value as base.u32),
|
||||
continued: 1,
|
||||
length: 4)
|
||||
continue.string_loop_outer
|
||||
// -------- END backslash-x
|
||||
}
|
||||
|
||||
@@ -658,8 +606,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
if string_length > 0 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: this.string_value_minor |
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY,
|
||||
continued: 1,
|
||||
length: string_length)
|
||||
@@ -694,8 +643,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
if string_length >= 0xFFF8 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: this.string_value_minor |
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY,
|
||||
continued: 1,
|
||||
length: string_length + 2)
|
||||
@@ -711,8 +661,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
if string_length > 0 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: this.string_value_minor |
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY,
|
||||
continued: 1,
|
||||
length: string_length)
|
||||
@@ -751,8 +702,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
if string_length >= 0xFFF8 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: this.string_value_minor |
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY,
|
||||
continued: 1,
|
||||
length: string_length + 3)
|
||||
@@ -769,8 +721,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
if string_length > 0 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: this.string_value_minor |
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY,
|
||||
continued: 1,
|
||||
length: string_length)
|
||||
@@ -808,8 +761,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
if string_length >= 0xFFF8 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: this.string_value_minor |
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY,
|
||||
continued: 1,
|
||||
length: string_length + 4)
|
||||
@@ -825,8 +779,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
if string_length > 0 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: this.string_value_minor |
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY,
|
||||
continued: 1,
|
||||
length: string_length)
|
||||
@@ -881,8 +836,9 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: this.string_value_minor |
|
||||
value_minor: (base.TOKEN__VBC__STRING << 21) |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8 |
|
||||
base.TOKEN__VBD__STRING__DEFINITELY_ASCII |
|
||||
base.TOKEN__VBD__STRING__CONVERT_0_DST_1_SRC_DROP,
|
||||
continued: 0,
|
||||
|
||||
@@ -75,19 +75,11 @@ pub const QUIRK_ALLOW_BACKSLASH_SINGLE_QUOTE : base.u32 = 0x4909_9400 | 0x06
|
||||
// character.
|
||||
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. It
|
||||
// decodes 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.
|
||||
//
|
||||
// It is up to the caller whether and how to run UTF-8 validation.
|
||||
//
|
||||
// There are exactly 2 encoded bytes after each "\x". "\x", "\x9", "\x9$" and
|
||||
// "\X99" are all still rejected.
|
||||
//
|
||||
// This quirk cannot be combined with QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS.
|
||||
pub const QUIRK_ALLOW_BACKSLASH_X_AS_BYTES : base.u32 = 0x4909_9400 | 0x08
|
||||
// (0x4909_9400 | 0x08) is reserved for QUIRK_ALLOW_BACKSLASH_X_AS_BYTES. This
|
||||
// quirk used to be implemented, but it was removed due to its complexity.
|
||||
// Enabling it (as a run-time option) meant that decoded JSON strings are no
|
||||
// longer guaranteed to be valid UTF-8. We could re-implement it if there is
|
||||
// sufficient demand.
|
||||
|
||||
// When this quirk is enabled, e.g. "abc\xeFz" is accepted as a JSON string. It
|
||||
// decodes to 6 bytes: 0x61, 0x62, 0x63, 0xC3, 0xAF and 0x7A. The UTF-8
|
||||
@@ -97,8 +89,6 @@ pub const QUIRK_ALLOW_BACKSLASH_X_AS_BYTES : base.u32 = 0x4909_9400 | 0x08
|
||||
//
|
||||
// There are exactly 2 encoded bytes after each "\x". "\x", "\x9", "\x9$" and
|
||||
// "\X99" are all still rejected.
|
||||
//
|
||||
// This quirk cannot be combined with QUIRK_ALLOW_BACKSLASH_X_AS_BYTES.
|
||||
pub const QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS : base.u32 = 0x4909_9400 | 0x09
|
||||
|
||||
// When this quirk is enabled, e.g. "abc\0z" is accepted as a JSON string,
|
||||
|
||||
Reference in new issue
Block a user