fix(json_family): Fix JSON.GET crash for the multiple legacy mode paths (#3582)

fixes dragonflydb#3558

Signed-off-by: Stepan Bagritsevich <stefan@dragonflydb.io>
This commit is contained in:
Stepan Bagritsevich 2024-08-27 18:20:34 +02:00 committed by GitHub
parent f4fd0f1a07
commit 832b79563d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View file

@ -572,7 +572,9 @@ OpResult<std::string> OpJsonGet(const OpArgs& op_args, string_view key,
} else {
for (const auto& [path_str, path] : paths) {
auto eval_result = eval_wrapped(path);
DCHECK(eval_result);
if (legacy_mode_is_enabled && !eval_result) {
return OpStatus::INVALID_JSON_PATH;
}
out[path_str] = std::move(eval_result).value(); // TODO(Print not existing path to the user)
}
}

View file

@ -152,6 +152,12 @@ TEST_F(JsonFamilyTest, GetLegacy) {
resp = Run({"JSON.GET", "json", "bar"}); // V1 Response
ASSERT_THAT(resp, ErrArg("ERR invalid JSON path"));
resp = Run({"JSON.GET", "json", ".", "bar"}); // V1 Response
ASSERT_THAT(resp, ErrArg("ERR invalid JSON path"));
resp = Run({"JSON.GET", "json", ".a", "bar", "foo", "third", "."}); // V1 Response
ASSERT_THAT(resp, ErrArg("ERR invalid JSON path"));
resp = Run({"JSON.GET", "json", "$.bar"}); // V2 Response
ASSERT_THAT(resp, "[]");