Fix nlohmann/json#3513, explain is_ndarray flag (#3514)

* Fix nlohmann/json#3513, explain is_ndarray flag

* add test for ndarray size following H
This commit is contained in:
Qianqian Fang
2022-06-03 02:51:33 -04:00
committed by GitHub
parent 6b97599a27
commit 046927cc29
3 changed files with 41 additions and 29 deletions

View File

@@ -2541,7 +2541,7 @@ TEST_CASE("BJData")
CHECK(json::from_bjdata(vI, true, false).is_discarded());
}
SECTION("do not accept NTFZ markers in ndarray optimized type")
SECTION("do not accept NTFZ markers in ndarray optimized type (with count)")
{
json _;
std::vector<uint8_t> v_N = {'[', '$', 'N', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2};
@@ -2562,7 +2562,7 @@ TEST_CASE("BJData")
CHECK(json::from_bjdata(v_Z, true, false).is_discarded());
}
SECTION("do not accept NTFZ markers in ndarray optimized type")
SECTION("do not accept NTFZ markers in ndarray optimized type (without count)")
{
json _;
std::vector<uint8_t> v_N = {'[', '$', 'N', '#', '[', 'i', 1, 'i', 2, ']'};
@@ -2746,7 +2746,7 @@ TEST_CASE("BJData")
CHECK(json::from_bjdata(vh, true, false).is_discarded());
std::vector<uint8_t> vR = {'[', '$', 'i', '#', '[', 'i', 1, '[', ']', ']', 1};
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR), "[json.exception.parse_error.113] parse error at byte 8: syntax error while parsing BJData size: ndarray dimention vector can only contain integers", json::parse_error&);
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR), "[json.exception.parse_error.113] parse error at byte 8: syntax error while parsing BJData size: ndarray dimentional vector is not allowed", json::parse_error&);
CHECK(json::from_bjdata(vR, true, false).is_discarded());
std::vector<uint8_t> vRo = {'[', '$', 'i', '#', '[', 'i', 0, '{', '}', ']', 1};
@@ -2754,7 +2754,7 @@ TEST_CASE("BJData")
CHECK(json::from_bjdata(vRo, true, false).is_discarded());
std::vector<uint8_t> vR1 = {'[', '$', 'i', '#', '[', '[', 'i', 1, ']', ']', 1};
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR1), "[json.exception.parse_error.113] parse error at byte 6: syntax error while parsing BJData size: ndarray dimention vector can only contain integers", json::parse_error&);
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR1), "[json.exception.parse_error.113] parse error at byte 6: syntax error while parsing BJData size: ndarray dimentional vector is not allowed", json::parse_error&);
CHECK(json::from_bjdata(vR1, true, false).is_discarded());
std::vector<uint8_t> vR2 = {'[', '$', 'i', '#', '[', '#', '[', 'i', 1, ']', ']', 1};
@@ -2770,12 +2770,16 @@ TEST_CASE("BJData")
CHECK(json::from_bjdata(vR4, true, false).is_discarded());
std::vector<uint8_t> vR5 = {'[', '$', 'i', '#', '[', '[', '[', ']', ']', ']'};
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR5), "[json.exception.parse_error.113] parse error at byte 6: syntax error while parsing BJData size: ndarray dimention vector can only contain integers", json::parse_error&);
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR5), "[json.exception.parse_error.113] parse error at byte 6: syntax error while parsing BJData size: ndarray dimentional vector is not allowed", json::parse_error&);
CHECK(json::from_bjdata(vR5, true, false).is_discarded());
std::vector<uint8_t> vR6 = {'[', '$', 'i', '#', '[', '$', 'i', '#', '[', 'i', '2', 'i', 2, ']'};
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR6), "[json.exception.parse_error.112] parse error at byte 14: syntax error while parsing BJData size: ndarray can not be recursive", json::parse_error&);
CHECK(json::from_bjdata(vR6, true, false).is_discarded());
std::vector<uint8_t> vH = {'[', 'H', '[', '#', '[', '$', 'i', '#', '[', 'i', '2', 'i', 2, ']'};
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vH), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing BJData size: ndarray dimentional vector is not allowed", json::parse_error&);
CHECK(json::from_bjdata(vH, true, false).is_discarded());
}
SECTION("objects")