diff --git a/include/simdjson/dom/array-inl.h b/include/simdjson/dom/array-inl.h index 8b1204236..70cf6a8e7 100644 --- a/include/simdjson/dom/array-inl.h +++ b/include/simdjson/dom/array-inl.h @@ -147,7 +147,7 @@ inline void array::process_json_path_of_child_elements(std::vector::ite for (auto it = current; it != end; ++it) { - result = current->at_path_with_wildcard(path_suffix); + result = it->at_path_with_wildcard(path_suffix); if (!result.error()) { std::vector child_result = result.value(); @@ -198,10 +198,12 @@ inline simdjson_result> array::at_path_with_wildcard(std::s std::vector result = {}; - std::vector::iterator child_values_begin = child_values.begin(); - std::vector::iterator child_values_end = child_values.end(); + if (child_values.size() > 0) { + std::vector::iterator child_values_begin = child_values.begin(); + std::vector::iterator child_values_end = child_values.end(); - process_json_path_of_child_elements(child_values_begin, child_values_end, "$" + std::string(json_path), result); + process_json_path_of_child_elements(child_values_begin, child_values_end, "$" + std::string(json_path), result); + } return result; } else { diff --git a/include/simdjson/dom/object-inl.h b/include/simdjson/dom/object-inl.h index baf0efe43..7fae523af 100644 --- a/include/simdjson/dom/object-inl.h +++ b/include/simdjson/dom/object-inl.h @@ -214,11 +214,14 @@ inline simdjson_result> object::at_path_with_wildcard(std:: } std::vector result = {}; + if (child_values.size() > 0) { - std::vector::iterator child_values_begin = child_values.begin(); - std::vector::iterator child_values_end = child_values.end(); + std::vector::iterator child_values_begin = child_values.begin(); + std::vector::iterator child_values_end = child_values.end(); + + process_json_path_of_child_elements(child_values_begin, child_values_end, "$" + std::string(json_path), result); + } - process_json_path_of_child_elements(child_values_begin, child_values_end, "$" + std::string(json_path), result); return result; } else { return INVALID_JSON_POINTER; @@ -226,7 +229,7 @@ inline simdjson_result> object::at_path_with_wildcard(std:: } else { auto at_path_result = this->at_path(json_path); if (at_path_result.error()) { - return INVALID_JSON_POINTER; + return at_path_result.error(); } std::vector result{std::move(at_path_result.value())}; return result; diff --git a/include/simdjson/jsonpathutil.h b/include/simdjson/jsonpathutil.h index e0a2ccce6..cc5e43936 100644 --- a/include/simdjson/jsonpathutil.h +++ b/include/simdjson/jsonpathutil.h @@ -82,7 +82,7 @@ inline std::pair get_next_key_and_json_path( } key = json_path.substr(key_start, i - key_start); - } else if (json_path[i] == '[' && (json_path[i+1] == '\'' || json_path[i+1] == '"')) { + } else if (json_path.size() > 1 && json_path[i] == '[' && (json_path[i+1] == '\'' || json_path[i+1] == '"')) { i += 2; size_t key_start = i; while (i < json_path.length() && json_path[i] != '\'' && json_path[i] != '"') { @@ -92,7 +92,7 @@ inline std::pair get_next_key_and_json_path( key = json_path.substr(key_start, i - key_start); i += 2; - } else if (json_path[i] == '[' && json_path[i+1] == '*' && json_path[i+2] == ']') { // i.e [*].additional_keys or [*]["additional_keys"] + } else if (json_path.size() >= 3 && json_path[i] == '[' && json_path[i+1] == '*' && json_path[i+2] == ']') { // i.e [*].additional_keys or [*]["additional_keys"] key = "*"; i += 3; } @@ -100,5 +100,7 @@ inline std::pair get_next_key_and_json_path( return std::make_pair(key, json_path.substr(i)); } + + } // namespace simdjson #endif // SIMDJSON_JSONPATHUTIL_H