Apply CRs

This commit is contained in:
wangyuan21 2021-11-01 18:57:03 +08:00
parent 1e69400369
commit d2b88ea5a8
2 changed files with 16 additions and 16 deletions

View File

@ -1535,6 +1535,8 @@ void Path::makePath(const String& path, const InArgs& in) {
++current; ++current;
} else { } else {
ArrayIndex index = 0; ArrayIndex index = 0;
if (current == end || *current < '0' || *current > '9')
invalidPath(path, int(current - path.c_str()));
for (; current != end && *current >= '0' && *current <= '9'; ++current) for (; current != end && *current >= '0' && *current <= '9'; ++current)
index = index * 10 + ArrayIndex(*current - '0'); index = index * 10 + ArrayIndex(*current - '0');
args_.push_back(index); args_.push_back(index);

View File

@ -2138,23 +2138,21 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, searchValueByPath) {
} }
{ {
const Json::String expected("{" const Json::String expected("{"
"\"property1\":[0,1,null]," "\"property1\":[0,1],"
"\"property2\":{" "\"property2\":{\"object\":\"object\"},"
"\"hello\":null," "\"property3\":[[0,1],[2,3]]"
"\"object\":\"object\"},"
"\"property3\":[[0,1,null],[2,3]]"
"}\n"); "}\n");
Json::Path path1(".property1.[%]", 2); Json::Path cases[] = {
Json::Value& value1 = path1.make(root); Json::Path(".property1.[%]", 2),
JSONTEST_ASSERT_EQUAL(Json::nullValue, value1); Json::Path(".property2.%", "hello"),
Json::Path(".property3.[0][%]", 2),
Json::Path path2(".property2.%", "hello"); };
Json::Value& value2 = path2.make(root); for (const auto& path : cases) {
JSONTEST_ASSERT_EQUAL(Json::nullValue, value2); Json::Value rootCopy(root);
Json::Value v(12345);
Json::Path path3(".property3[0][%]", 2); path.make(rootCopy) = v;
Json::Value& value3 = path3.make(root); JSONTEST_ASSERT_EQUAL(path.resolve(rootCopy), v);
JSONTEST_ASSERT_EQUAL(Json::nullValue, value3); };
// make will change the value // make will change the value
const Json::String outcome = writer.write(root); const Json::String outcome = writer.write(root);