mirror of
https://github.com/postgres/postgres.git
synced 2025-11-07 19:06:32 +03:00
SQL/JSON: Correct jsonpath variable name matching
Previously, GetJsonPathVar() allowed a jsonpath expression to reference any prefix of a PASSING variable's name. For example, the following query would incorrectly work: SELECT JSON_QUERY(context_item, jsonpath '$xy' PASSING val AS xyz); The fix ensures that the length of the variable name mentioned in a jsonpath expression matches exactly with the name of the PASSING variable before comparing the strings using strncmp(). Reported-by: Alvaro Herrera (off-list) Discussion: https://postgr.es/m/CA+HiwqFGkLWMvELBH6E4SQ45qUHthgcRH6gCJL20OsYDRtFx_w@mail.gmail.com
This commit is contained in:
@@ -454,3 +454,8 @@ SELECT JSON_QUERY(NULL FORMAT JSON, '$');
|
||||
-- Test non-const jsonpath
|
||||
CREATE TEMP TABLE jsonpaths (path) AS SELECT '$';
|
||||
SELECT json_value('"aaa"', path RETURNING json) FROM jsonpaths;
|
||||
|
||||
-- Test PASSING argument parsing
|
||||
SELECT JSON_QUERY(jsonb 'null', '$xyz' PASSING 1 AS xy);
|
||||
SELECT JSON_QUERY(jsonb 'null', '$xy' PASSING 1 AS xyz);
|
||||
SELECT JSON_QUERY(jsonb 'null', '$xyz' PASSING 1 AS xyz);
|
||||
|
||||
Reference in New Issue
Block a user