From 1b54cae8c85cc40fa237b5f3bc060a5e68fe28ca Mon Sep 17 00:00:00 2001 From: Uniplore-X <123929969+Uniplore-X@users.noreply.github.com> Date: Fri, 25 Oct 2024 11:22:51 +0800 Subject: [PATCH] unexpected behavior for built-in function `join` of jmespath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unexpected behavior `join`,when elements are empty strings ahead of the json array. For example: `join(',', @)` --- ["", "", "a", "","b", "c", ""] --- current result is: a,,b,c, but expected: ,,a,,b,c, --- include/jsoncons_ext/jmespath/jmespath.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/jsoncons_ext/jmespath/jmespath.hpp b/include/jsoncons_ext/jmespath/jmespath.hpp index 8c40b99bb..edc81bdda 100644 --- a/include/jsoncons_ext/jmespath/jmespath.hpp +++ b/include/jsoncons_ext/jmespath/jmespath.hpp @@ -1001,17 +1001,24 @@ namespace jmespath { string_type sep = arg0.template as(); string_type buf; - for (auto& j : arg1.array_range()) + bool is_first = true; + for (auto &j : arg1.array_range()) { if (!j.is_string()) { ec = jmespath_errc::invalid_type; return resources.null_value(); } - if (!buf.empty()) + + if (is_first) + { + is_first = false; + } + else { buf.append(sep); } + auto sv = j.template as(); buf.append(sv.begin(), sv.end()); }