This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new 5611a3988b4 [Fix](JsonPath) return null when meet unknown escape 
sequence, example '$.name\\k' (#50930)
5611a3988b4 is described below

commit 5611a3988b4dd8f34a36b09972e864dedac2e479
Author: lihangyu <[email protected]>
AuthorDate: Sat May 17 17:21:22 2025 +0800

    [Fix](JsonPath) return null when meet unknown escape sequence, example 
'$.name\\k' (#50930)
    
    cherry-pick from #50859
---
 be/src/vec/functions/function_json.cpp               |  19 ++++++++++++-------
 .../json_functions/test_json_function.out            | Bin 1295 -> 1341 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 44830340822..346c6005b98 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"
@@ -237,16 +238,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 45d1d1b9e03..fddcd249f4c 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 20ef0843e39..be4076020f0 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
@@ -79,4 +79,9 @@ suite("test_json_function", "arrow_flight_sql") {
     qt_sql """SELECT JSON_CONTAINS("",'1','\$.a')"""
 
     qt_sql """select k6, json_extract_string(cast(k7 as json), "\$.a") as x10 
from test_query_db.baseall group by k6, x10 order by 1,2; """
+
+    // 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]

Reply via email to