Skip to content

Commit 1aa506b

Browse files
author
Bartel Van Nieuwenhuyse
committed
Do a shallow copy of the first argument to the merge function: if it is a json_const_ref no modification of the referenced json is allowed.
1 parent 6eae7fa commit 1aa506b

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

include/jsoncons_ext/jmespath/jmespath.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,8 +2022,9 @@ namespace detail {
20222022
return arg0;
20232023
}
20242024

2025-
auto result = context.create_json(arg0);
2026-
for (std::size_t i = 1; i < args.size(); ++i)
2025+
auto result = context.create_json(json_object_arg);
2026+
result->reserve(arg0.size());
2027+
for (std::size_t i = 0; i < args.size(); ++i)
20272028
{
20282029
reference argi = args[i].value();
20292030
if (!argi.is_object())

test/jmespath/input/test.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
[
2+
{
3+
"given": {
4+
"foz": "baz"
5+
},
6+
"cases": [
7+
{
8+
"comment": "Multi select hash used in merge function",
9+
"expression": "{object:@}.merge(object, {foo:'bar'})",
10+
"result": {
11+
"foo": "bar",
12+
"foz": "baz"
13+
}
14+
}
15+
]
16+
},
217
{
318
"given": [
419
{ "foo": "bar" },

0 commit comments

Comments
 (0)