mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
fix bug with array, add boundary check to get_next_key_and_json_path function
This commit is contained in:
@@ -147,7 +147,7 @@ inline void array::process_json_path_of_child_elements(std::vector<element>::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<element> child_result = result.value();
|
||||
@@ -198,10 +198,12 @@ inline simdjson_result<std::vector<element>> array::at_path_with_wildcard(std::s
|
||||
|
||||
std::vector<element> result = {};
|
||||
|
||||
std::vector<element>::iterator child_values_begin = child_values.begin();
|
||||
std::vector<element>::iterator child_values_end = child_values.end();
|
||||
if (child_values.size() > 0) {
|
||||
std::vector<element>::iterator child_values_begin = child_values.begin();
|
||||
std::vector<element>::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 {
|
||||
|
||||
@@ -214,11 +214,14 @@ inline simdjson_result<std::vector<element>> object::at_path_with_wildcard(std::
|
||||
}
|
||||
|
||||
std::vector<element> result = {};
|
||||
if (child_values.size() > 0) {
|
||||
|
||||
std::vector<element>::iterator child_values_begin = child_values.begin();
|
||||
std::vector<element>::iterator child_values_end = child_values.end();
|
||||
std::vector<element>::iterator child_values_begin = child_values.begin();
|
||||
std::vector<element>::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<std::vector<element>> 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<element> result{std::move(at_path_result.value())};
|
||||
return result;
|
||||
|
||||
@@ -82,7 +82,7 @@ inline std::pair<std::string_view, std::string_view> 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<std::string_view, std::string_view> 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<std::string_view, std::string_view> get_next_key_and_json_path(
|
||||
return std::make_pair(key, json_path.substr(i));
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace simdjson
|
||||
#endif // SIMDJSON_JSONPATHUTIL_H
|
||||
|
||||
Reference in New Issue
Block a user