mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 16:47:28 +01:00
Add std/json quirk_allow_inf_nan_numbers
This commit is contained in:
1 parent
b43e2493a2
commit
d7c72373f3
6 files changed
+436
-17
No files matched your search
@@ -196,7 +196,7 @@ pri const lut_chars array[256] base.u8 = [
|
||||
// - 0x08 (bitmask 0x0100) is CLASS_CLOSE_SQUARE_BRACKET.
|
||||
// - 0x09 (bitmask 0x0200) is CLASS_FALSE.
|
||||
// - 0x0A (bitmask 0x0400) is CLASS_TRUE.
|
||||
// - 0x0B (bitmask 0x0800) is CLASS_NULL.
|
||||
// - 0x0B (bitmask 0x0800) is CLASS_NULL_NAN_INF.
|
||||
// - 0x0C (bitmask 0x1000) is CLASS_COMMENT.
|
||||
// - 0x0D (bitmask 0x2000) is reserved.
|
||||
// - 0x0E (bitmask 0x4000) is reserved.
|
||||
@@ -236,16 +236,16 @@ pri const lut_classes array[256] base.u8[..= 0x0F] = [
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // 0x10 ..= 0x17.
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // 0x18 ..= 0x1F.
|
||||
0x00, 0x0F, 0x01, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // 0x20 ..= 0x27. ' ', '"'.
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x02, 0x04, 0x0F, 0x0C, // 0x28 ..= 0x2F. ',', '-', '/'.
|
||||
0x0F, 0x0F, 0x0F, 0x0B, 0x02, 0x04, 0x0F, 0x0C, // 0x28 ..= 0x2F. '+', ',', '-', '/'.
|
||||
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, // 0x30 ..= 0x37. '0'-'7'.
|
||||
0x04, 0x04, 0x03, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // 0x38 ..= 0x3F. '8'-'9', ':'.
|
||||
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // 0x40 ..= 0x47.
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // 0x48 ..= 0x4F.
|
||||
0x0F, 0x0B, 0x0F, 0x0F, 0x0F, 0x0F, 0x0B, 0x0F, // 0x48 ..= 0x4F. 'I', 'N'.
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // 0x50 ..= 0x57.
|
||||
0x0F, 0x0F, 0x0F, 0x07, 0x0F, 0x08, 0x0F, 0x0F, // 0x58 ..= 0x5F. '[', ']'.
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x09, 0x0F, // 0x60 ..= 0x67. 'f'.
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0B, 0x0F, // 0x68 ..= 0x6F. 'n'.
|
||||
0x0F, 0x0B, 0x0F, 0x0F, 0x0F, 0x0F, 0x0B, 0x0F, // 0x68 ..= 0x6F. 'i', 'n'.
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0A, 0x0F, 0x0F, 0x0F, // 0x70 ..= 0x77. 't'.
|
||||
0x0F, 0x0F, 0x0F, 0x05, 0x0F, 0x06, 0x0F, 0x0F, // 0x78 ..= 0x7F. '{', '}'.
|
||||
|
||||
|
||||
+115
-1
@@ -888,6 +888,10 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
|
||||
if number_status == 1 {
|
||||
if this.quirk_enabled_allow_inf_nan_numbers {
|
||||
this.decode_inf_nan?(dst: args.dst, src: args.src)
|
||||
break
|
||||
}
|
||||
return "#bad input"
|
||||
} else if number_status == 2 {
|
||||
return "#unsupported number length"
|
||||
@@ -1061,7 +1065,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
continue.outer
|
||||
}
|
||||
|
||||
} else if class == 0x0B { // 0x0B is CLASS_NULL.
|
||||
} else if class == 0x0B { // 0x0B is CLASS_NULL_NAN_INF.
|
||||
match = args.src.match7(a: 0x6C_6C75_6E04) // 4 bytes "null".
|
||||
if match == 0 {
|
||||
args.dst.write_fast_token!(
|
||||
@@ -1079,6 +1083,11 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
continue.outer
|
||||
}
|
||||
|
||||
if this.quirk_enabled_allow_inf_nan_numbers {
|
||||
this.decode_inf_nan?(dst: args.dst, src: args.src)
|
||||
break.goto_parsed_a_leaf_value
|
||||
}
|
||||
|
||||
} else if class == 0x0C { // 0x0C is CLASS_COMMENT.
|
||||
if this.quirk_enabled_allow_comment_block or this.quirk_enabled_allow_comment_line {
|
||||
this.decode_comment?(dst: args.dst, src: args.src)
|
||||
@@ -1463,6 +1472,111 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
return "#bad input"
|
||||
}
|
||||
|
||||
pri func decoder.decode_inf_nan?(dst: base.token_writer, src: base.io_reader) {
|
||||
var c4 : base.u32
|
||||
var neg : base.u32[..= 1]
|
||||
|
||||
while true {
|
||||
if args.dst.available() <= 0 {
|
||||
yield? base."$short write"
|
||||
continue
|
||||
}
|
||||
if args.src.available() <= 2 {
|
||||
if args.src.is_closed() {
|
||||
return "#bad input"
|
||||
}
|
||||
yield? base."$short read"
|
||||
continue
|
||||
}
|
||||
|
||||
// Bitwise or'ing with 0x20 converts upper case ASCII to lower case.
|
||||
|
||||
c4 = args.src.peek_u24le_as_u32()
|
||||
if (c4 | 0x20_2020) == 0x66_6E69 {
|
||||
if args.src.available() > 7 {
|
||||
if (args.src.peek_u64le() | 0x2020_2020_2020_2020) == 0x7974_696E_6966_6E69 {
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0,
|
||||
value_minor: 0xA0_0020,
|
||||
link: 0x0,
|
||||
length: 8)
|
||||
args.src.skip32_fast!(actual: 8, worst_case: 8)
|
||||
return ok
|
||||
}
|
||||
} else if not args.src.is_closed() {
|
||||
yield? base."$short read"
|
||||
continue
|
||||
}
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0,
|
||||
value_minor: 0xA0_0020,
|
||||
link: 0x0,
|
||||
length: 3)
|
||||
args.src.skip32_fast!(actual: 3, worst_case: 3)
|
||||
return ok
|
||||
|
||||
} else if (c4 | 0x20_2020) == 0x6E_616E {
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0,
|
||||
value_minor: 0xA0_0080,
|
||||
link: 0x0,
|
||||
length: 3)
|
||||
args.src.skip32_fast!(actual: 3, worst_case: 3)
|
||||
return ok
|
||||
} else if (c4 & 0xFF) == 0x2B { // 0x2B is '+'.
|
||||
neg = 0
|
||||
} else if (c4 & 0xFF) == 0x2D { // 0x2D is '-'.
|
||||
neg = 1
|
||||
} else {
|
||||
return "#bad input"
|
||||
}
|
||||
|
||||
if args.src.available() <= 3 {
|
||||
if args.src.is_closed() {
|
||||
return "#bad input"
|
||||
}
|
||||
yield? base."$short read"
|
||||
continue
|
||||
}
|
||||
|
||||
c4 = args.src.peek_u32le() >> 8
|
||||
if (c4 | 0x20_2020) == 0x66_6E69 {
|
||||
if args.src.available() > 8 {
|
||||
if (args.src.peek_u64le_at(offset: 1) | 0x2020_2020_2020_2020) == 0x7974_696E_6966_6E69 {
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0,
|
||||
value_minor: 0xA0_0000 | ((0x20 as base.u32) >> neg),
|
||||
link: 0x0,
|
||||
length: 9)
|
||||
args.src.skip32_fast!(actual: 9, worst_case: 9)
|
||||
return ok
|
||||
}
|
||||
} else if not args.src.is_closed() {
|
||||
yield? base."$short read"
|
||||
continue
|
||||
}
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0,
|
||||
value_minor: 0xA0_0000 | ((0x20 as base.u32) >> neg),
|
||||
link: 0x0,
|
||||
length: 4)
|
||||
args.src.skip32_fast!(actual: 4, worst_case: 4)
|
||||
return ok
|
||||
|
||||
} else if (c4 | 0x20_2020) == 0x6E_616E {
|
||||
args.dst.write_fast_token!(
|
||||
value_major: 0,
|
||||
value_minor: 0xA0_0000 | ((0x80 as base.u32) >> neg),
|
||||
link: 0x0,
|
||||
length: 4)
|
||||
args.src.skip32_fast!(actual: 4, worst_case: 4)
|
||||
return ok
|
||||
}
|
||||
|
||||
return "#bad input"
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_trailing_new_line?(dst: base.token_writer, src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var whitespace_length : base.u32[..= 0xFFFE]
|
||||
|
||||
Reference in new issue
Block a user