chore: doc_accessors now parse with json::Path as well (#2615)

chore: replace search path parsing with json::Path

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2024-02-20 19:58:22 +02:00 committed by GitHub
parent 8cce14ce85
commit cbfd5bb7c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 58 additions and 49 deletions

View file

@ -15,9 +15,8 @@
#include "base/flags.h"
#include "base/logging.h"
#include "core/json/driver.h"
#include "core/json/json_object.h"
#include "core/json/jsonpath_grammar.hh"
#include "core/json/path.h"
#include "facade/cmd_arg_parser.h"
#include "facade/op_status.h"
#include "server/acl/acl_commands_def.h"
@ -62,29 +61,6 @@ inline void Evaluate(const json::Path& expr, const JsonType& obj, ExprCallback c
});
}
class JsonPathDriver : public json::Driver {
public:
string msg;
void Error(const json::location& l, const std::string& msg) final {
this->msg = absl::StrCat("Error: ", msg);
}
};
io::Result<json::Path, string> JsonPathV2Parse(string_view path) {
if (path.size() > 8_KB)
return nonstd::make_unexpected("Path too long");
JsonPathDriver driver;
json::Parser parser(&driver);
driver.SetInput(string(path));
int res = parser();
if (res != 0) {
return nonstd::make_unexpected(driver.msg);
}
return driver.TakePath();
}
inline OpStatus JsonReplaceVerifyNoOp(JsonType&) {
return OpStatus::OK;
}
@ -1206,7 +1182,7 @@ OpResult<bool> OpSet(const OpArgs& op_args, string_view key, string_view path,
io::Result<JsonPathV2, string> ParsePathV2(string_view path) {
if (absl::GetFlag(FLAGS_jsonpathv2)) {
return JsonPathV2Parse(path);
return json::ParsePath(path);
}
io::Result<JsonExpression> expr_result = ParseJsonPath(path);
if (!expr_result) {