This is an automated email from the ASF dual-hosted git repository.
eldenmoon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 522e7cef55a [Fix](JsonPath) return null when meet unknown escape
sequence, example '$.name\\k' (#50859)
522e7cef55a is described below
commit 522e7cef55ae64e0d4d6a6891749b7e10bfa0729
Author: lihangyu <[email protected]>
AuthorDate: Wed May 14 10:04:54 2025 +0800
[Fix](JsonPath) return null when meet unknown escape sequence, example
'$.name\\k' (#50859)
---
be/src/vec/functions/function_json.cpp | 19 ++++++++++++-------
.../json_functions/test_json_function.out | Bin 1428 -> 1476 bytes
.../json_functions/test_json_function.groovy | 5 +++++
3 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/be/src/vec/functions/function_json.cpp
b/be/src/vec/functions/function_json.cpp
index 84e8571782a..4d27b549996 100644
--- a/be/src/vec/functions/function_json.cpp
+++ b/be/src/vec/functions/function_json.cpp
@@ -39,6 +39,7 @@
#include <vector>
#include "common/compiler_util.h" // IWYU pragma: keep
+#include "common/exception.h"
#include "common/status.h"
#include "exprs/json_functions.h"
#include "vec/io/io_helper.h"
@@ -238,16 +239,20 @@ rapidjson::Value* get_json_object(std::string_view
json_string, std::string_view
return document;
}
+ try {
#ifdef USE_LIBCPP
- std::string s(path_string);
- auto tok = get_json_token(s);
+ std::string s(path_string);
+ auto tok = get_json_token(s);
#else
- auto tok = get_json_token(path_string);
+ auto tok = get_json_token(path_string);
#endif
-
- std::vector<std::string> paths(tok.begin(), tok.end());
- get_parsed_paths(paths, &tmp_parsed_paths);
- if (tmp_parsed_paths.empty()) {
+ std::vector<std::string> paths(tok.begin(), tok.end());
+ get_parsed_paths(paths, &tmp_parsed_paths);
+ if (tmp_parsed_paths.empty()) {
+ return document;
+ }
+ } catch (boost::escaped_list_error&) {
+ // meet unknown escape sequence, example '$.name\k'
return document;
}
diff --git
a/regression-test/data/query_p0/sql_functions/json_functions/test_json_function.out
b/regression-test/data/query_p0/sql_functions/json_functions/test_json_function.out
index 1ec59c120dc..c22acc17134 100644
Binary files
a/regression-test/data/query_p0/sql_functions/json_functions/test_json_function.out
and
b/regression-test/data/query_p0/sql_functions/json_functions/test_json_function.out
differ
diff --git
a/regression-test/suites/query_p0/sql_functions/json_functions/test_json_function.groovy
b/regression-test/suites/query_p0/sql_functions/json_functions/test_json_function.groovy
index 74545d6046d..fe4dfc55315 100644
---
a/regression-test/suites/query_p0/sql_functions/json_functions/test_json_function.groovy
+++
b/regression-test/suites/query_p0/sql_functions/json_functions/test_json_function.groovy
@@ -86,4 +86,9 @@ suite("test_json_function", "arrow_flight_sql") {
qt_sql "SELECT json_extract_no_quotes(null, '\$.id');"
qt_sql "SELECT json_extract_no_quotes('{\"k1\": \"v1\", \"k2\": { \"k21\":
6.6, \"k22\": [1, 2, 3] } }', '\$.k1', '\$.k2');"
qt_sql "SELECT json_extract_no_quotes('{\"k1\": \"v1\", \"k2\": { \"k21\":
6.6, \"k22\": [1, 2, 3] } }', '\$.k2.k21', '\$.k2.k22', '\$.k2.k22[1]');"
+
+ // invalid json path
+ qt_sql """select get_json_string('{"name\\k" : 123}', '\$.name\\k')"""
+ qt_sql """select get_json_string('{"name\\k" : 123}', '\$.name\\\\k')"""
+ qt_sql """select get_json_string('{"name\\k" : 123}', '\$.name\\\\\\k')"""
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]