From d2b88ea5a8ca2b874259f4216156d769de7cdf67 Mon Sep 17 00:00:00 2001 From: wangyuan21 Date: Mon, 1 Nov 2021 18:57:03 +0800 Subject: [PATCH] Apply CRs --- src/lib_json/json_value.cpp | 2 ++ src/test_lib_json/main.cpp | 30 ++++++++++++++---------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index e234477..6c9109d 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1535,6 +1535,8 @@ void Path::makePath(const String& path, const InArgs& in) { ++current; } else { 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) index = index * 10 + ArrayIndex(*current - '0'); args_.push_back(index); diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index 07b9a5b..edcd349 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -2138,23 +2138,21 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, searchValueByPath) { } { const Json::String expected("{" - "\"property1\":[0,1,null]," - "\"property2\":{" - "\"hello\":null," - "\"object\":\"object\"}," - "\"property3\":[[0,1,null],[2,3]]" + "\"property1\":[0,1]," + "\"property2\":{\"object\":\"object\"}," + "\"property3\":[[0,1],[2,3]]" "}\n"); - Json::Path path1(".property1.[%]", 2); - Json::Value& value1 = path1.make(root); - JSONTEST_ASSERT_EQUAL(Json::nullValue, value1); - - Json::Path path2(".property2.%", "hello"); - Json::Value& value2 = path2.make(root); - JSONTEST_ASSERT_EQUAL(Json::nullValue, value2); - - Json::Path path3(".property3[0][%]", 2); - Json::Value& value3 = path3.make(root); - JSONTEST_ASSERT_EQUAL(Json::nullValue, value3); + Json::Path cases[] = { + Json::Path(".property1.[%]", 2), + Json::Path(".property2.%", "hello"), + Json::Path(".property3.[0][%]", 2), + }; + for (const auto& path : cases) { + Json::Value rootCopy(root); + Json::Value v(12345); + path.make(rootCopy) = v; + JSONTEST_ASSERT_EQUAL(path.resolve(rootCopy), v); + }; // make will change the value const Json::String outcome = writer.write(root);