SQL/JSON: Correct jsonpath variable name matching

Amit Langote <amitlan@postgresql.org>

Commit: 0f271e8e8d9c8db0ea86c0d12b3221009b81d8bf
Author: Amit Langote <amitlan@postgresql.org>
Date: 2024-06-19T06:22:06Z
Releases: 17.0
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

Files

Discussion