diff --git a/Cargo.lock b/Cargo.lock index 722b0623c58..7986a28f6c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7622,7 +7622,7 @@ dependencies = [ [[package]] name = "jsonb" version = "0.5.6" -source = "git+https://github.com/GreptimeTeam/jsonb?rev=5a6472858d860ac034075c17253f41617bdfa956#5a6472858d860ac034075c17253f41617bdfa956" +source = "git+https://github.com/GreptimeTeam/jsonb?rev=ae1ca9a26c65902dac9b53864bf502843c312ea5#ae1ca9a26c65902dac9b53864bf502843c312ea5" dependencies = [ "byteorder", "ethnum", diff --git a/Cargo.toml b/Cargo.toml index f6b7a6812e1..4e2597d2b31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -177,7 +177,7 @@ icu_properties = "2.0.1" indicatif = "0.17" intern-arc = "0.6.2" itertools = "0.14" -jsonb = { git = "https://github.com/GreptimeTeam/jsonb", rev = "5a6472858d860ac034075c17253f41617bdfa956", default-features = false, features = [ +jsonb = { git = "https://github.com/GreptimeTeam/jsonb", rev = "ae1ca9a26c65902dac9b53864bf502843c312ea5", default-features = false, features = [ "databend", ] } lazy_static = "1.4" diff --git a/src/datatypes/src/types/json_type.rs b/src/datatypes/src/types/json_type.rs index f7f51b74016..8f3446c3eb9 100644 --- a/src/datatypes/src/types/json_type.rs +++ b/src/datatypes/src/types/json_type.rs @@ -442,6 +442,21 @@ mod tests { } } + #[test] + fn test_parse_json_rejects_integers_out_of_range() { + for input in [ + "18446744073709551616", + "-9223372036854775809", + r#"{"n": 123456789012345678901234567890}"#, + ] { + assert!(parse_string_to_jsonb(input).is_err(), "{input}"); + } + for input in ["18446744073709551615", "-9223372036854775808"] { + let jsonb = parse_string_to_jsonb(input).unwrap(); + assert_eq!(jsonb_to_string(&jsonb).unwrap(), input); + } + } + #[test] fn test_v2_jsonb_to_serde_json_escaped_keys() -> std::result::Result<(), Box> { diff --git a/tests/cases/standalone/common/types/json/json.result b/tests/cases/standalone/common/types/json/json.result index ae2587a745a..4054bc57ea6 100644 --- a/tests/cases/standalone/common/types/json/json.result +++ b/tests/cases/standalone/common/types/json/json.result @@ -129,6 +129,14 @@ INSERT INTO jsons VALUES(parse_json('Morning my friends, have a nice day :)'), 5 Error: 3001(EngineExecuteQuery), Execution error: cannot parse 'Morning my friends, have a nice day :)': expected value, pos 1 +INSERT INTO jsons VALUES(parse_json('{"n": 18446744073709551616}'), 6); + +Error: 3001(EngineExecuteQuery), Execution error: cannot parse '{"n": 18446744073709551616}': invalid number, pos 26 + +INSERT INTO jsons VALUES('{"n": -9223372036854775809}', 7); + +Error: 1004(InvalidArguments), Invalid JSON: {"n": -9223372036854775809} + SELECT json_to_string(j), t FROM jsons; +-------------------------+---+ diff --git a/tests/cases/standalone/common/types/json/json.sql b/tests/cases/standalone/common/types/json/json.sql index 5a521ee1c6d..1034158edbe 100644 --- a/tests/cases/standalone/common/types/json/json.sql +++ b/tests/cases/standalone/common/types/json/json.sql @@ -85,6 +85,10 @@ INSERT INTO jsons VALUES(parse_json('{"a":1, "b":2, "c":3'), 4); INSERT INTO jsons VALUES(parse_json('Morning my friends, have a nice day :)'), 5); +INSERT INTO jsons VALUES(parse_json('{"n": 18446744073709551616}'), 6); + +INSERT INTO jsons VALUES('{"n": -9223372036854775809}', 7); + SELECT json_to_string(j), t FROM jsons; CREATE TABLE json_empty (j JSON, t timestamp time index);