[MDEV-32007] JSON_VALUE and JSON_EXTRACT doesn't handle dash (-) as first character in key Created: 2023-08-24  Updated: 2023-11-13  Resolved: 2023-11-03

Status: Closed
Project: MariaDB Server
Component/s: JSON
Affects Version/s: 11.0.2
Fix Version/s: 11.0.5, 11.1.4, 11.2.3

Type: Bug Priority: Critical
Reporter: Dave Shenk Assignee: Rucha Deodhar
Resolution: Fixed Votes: 1
Labels: None
Environment:

MariaDB 11.0.2 running on MacOS; installed using homebrew


Issue Links:
Relates
relates to MDEV-29381 JSON paths containing dashes are repo... Closed
relates to MDEV-29586 JSON_VALUE and JSON_EXTRACT doesn't h... Closed

 Description   

11.0.2 doesn't seem to handle dashes when supplied as the first character of the JSON key. In JSON_VALUE and JSON_EXTRACT functions - it returns NULL even when the key is provided using the expected quoting.

CREATE TEMPORARY TABLE IF NOT EXISTS jsonTest AS
	SELECT '{ "-1234" : "something", "12-34" : "else", "1234-" : "and", "1234" : "match" }' AS 'message'
;
 
SELECT	JSON_SEARCH(message, 'one', 'something') AS t1_path, JSON_VALUE(message, JSON_UNQUOTE(JSON_SEARCH(message, 'one', 'something'))) AS t1_result,
	JSON_SEARCH(message, 'one', 'else') AS t2_path, JSON_VALUE(message, JSON_UNQUOTE(JSON_SEARCH(message, 'one', 'else'))) AS t2_result,
	JSON_SEARCH(message, 'one', 'and') AS t3_path, JSON_VALUE(message, JSON_UNQUOTE(JSON_SEARCH(message, 'one', 'and'))) AS t3_result,
	JSON_SEARCH(message, 'one', 'match') AS t4_path, JSON_VALUE(message, JSON_UNQUOTE(JSON_SEARCH(message, 'one', 'match'))) AS t4_result
FROM jsonTest
;

t1_path t1_result t2_path t2_result t3_path t3_result t4_path t4_result
"$.-1234" NULL "$.12-34" else "$.1234-" and "$.1234" match

Referencing related tickets that don't quite solve this scenario.



 Comments   
Comment by Rucha Deodhar [ 2023-09-25 ]

patch: https://github.com/MariaDB/server/commit/9973c6d0898b3369869ec9ee8d84068c8e9c4111

Comment by Alexey Botchkov [ 2023-10-30 ]

ok to push.

Comment by Rucha Deodhar [ 2023-11-03 ]

julien.fritsch , yes they were missing. thanks for adding.

Generated at Thu Feb 08 10:28:06 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.