Skip to content

Commit ffd7d95

Browse files
committed
Fix issue with jsonpointer remove
1 parent d78b5ac commit ffd7d95

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

include/jsoncons_ext/jsonpointer/jsonpointer.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,10 @@ namespace jsonpointer {
799799
bool create_if_missing,
800800
std::error_code& ec)
801801
{
802+
if (location.empty())
803+
{
804+
return;
805+
}
802806
Json* current = std::addressof(root);
803807

804808
std::basic_string<typename Json::char_type> buffer;
@@ -940,6 +944,7 @@ namespace jsonpointer {
940944
{
941945
if (location.empty())
942946
{
947+
ec = jsonpointer_errc::expected_location;
943948
return;
944949
}
945950

@@ -1047,6 +1052,11 @@ namespace jsonpointer {
10471052
bool create_if_missing,
10481053
std::error_code& ec)
10491054
{
1055+
if (location.empty())
1056+
{
1057+
root = std::forward<T>(value);
1058+
return;
1059+
}
10501060
Json* current = std::addressof(root);
10511061

10521062
std::basic_string<typename Json::char_type> buffer;

include/jsoncons_ext/jsonpointer/jsonpointer_error.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ enum class jsonpointer_errc
5555
unexpected_end_of_input,
5656
argument_to_unflatten_invalid,
5757
invalid_flattened_key,
58-
invalid_uri_escaped_data
58+
invalid_uri_escaped_data,
59+
expected_location
5960
};
6061

6162
class jsonpointer_error_category_impl
@@ -92,6 +93,8 @@ class jsonpointer_error_category_impl
9293
return "Argument to unflatten must be an object";
9394
case jsonpointer_errc::invalid_flattened_key:
9495
return "Flattened key is invalid";
96+
case jsonpointer_errc::expected_location:
97+
return "Expected location";
9598
default:
9699
return "Unknown jsonpointer error";
97100
}

0 commit comments

Comments
 (0)