mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
parser.load(string_view) does not respect view length when opening files (#2659)
This commit is contained in:
@@ -36,10 +36,11 @@ inline bool parser::dump_raw_tape(std::ostream &os) const noexcept {
|
||||
}
|
||||
|
||||
inline simdjson_result<size_t> parser::read_file(std::string_view path) noexcept {
|
||||
const std::string path_copy(path);
|
||||
// Open the file
|
||||
SIMDJSON_PUSH_DISABLE_WARNINGS
|
||||
SIMDJSON_DISABLE_DEPRECATED_WARNING // Disable CRT_SECURE warning on MSVC: manually verified this is safe
|
||||
std::FILE *fp = std::fopen(path.data(), "rb");
|
||||
std::FILE *fp = std::fopen(path_copy.c_str(), "rb");
|
||||
SIMDJSON_POP_DISABLE_WARNINGS
|
||||
|
||||
if (fp == nullptr) {
|
||||
|
||||
@@ -114,6 +114,20 @@ namespace parser_load {
|
||||
TEST_SUCCEED();
|
||||
}
|
||||
|
||||
bool parser_load_string_view_subpath() {
|
||||
TEST_START();
|
||||
const std::string valid_path(TWITTER_JSON);
|
||||
const std::string backing = valid_path + ".extra";
|
||||
const std::string_view view(backing.data(), valid_path.size());
|
||||
uint64_t count_from_string = 0;
|
||||
uint64_t count_from_view = 0;
|
||||
dom::parser parser;
|
||||
ASSERT_SUCCESS(parser.load(valid_path)["search_metadata"]["count"].get(count_from_string));
|
||||
ASSERT_SUCCESS(parser.load(view)["search_metadata"]["count"].get(count_from_view));
|
||||
ASSERT_EQUAL(count_from_view, count_from_string);
|
||||
TEST_SUCCEED();
|
||||
}
|
||||
|
||||
bool parser_load_chain() {
|
||||
TEST_START();
|
||||
dom::parser parser;
|
||||
@@ -136,6 +150,7 @@ namespace parser_load {
|
||||
&& parser_load_nonexistent()
|
||||
&& parser_load_many_nonexistent()
|
||||
&& padded_string_load_nonexistent()
|
||||
&& parser_load_string_view_subpath()
|
||||
&& parser_load_chain()
|
||||
&& parser_load_many_chain()
|
||||
&& parser_parse_many_documents_error_in_the_middle()
|
||||
|
||||
Reference in New Issue
Block a user