Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
ae01f96c4d5c02c973f5bac9e8c4ab82b5dac3a7 (latest origin/main tested on 2026-08-21)
Other Environment Information
- Hardware parameters: local development machine
- OS type: macOS
- Others: local single-process MatrixOne; MySQL text protocol on 127.0.0.1:6001. A deterministic Kafka/GH Archive stream was used for impact validation.
Actual Behavior
JSON-to-string conversion loses data when the JSON string payload itself begins and ends with a double quote.
SELECT
json_object('v', concat(char(34), 'x', char(34))) AS doc,
json_extract(json_object('v', concat(char(34), 'x', char(34))), '$.v') AS extracted,
json_unquote(json_extract(json_object('v', concat(char(34), 'x', char(34))), '$.v')) AS actual,
hex(json_unquote(json_extract(json_object('v', concat(char(34), 'x', char(34))), '$.v'))) AS actual_hex,
hex('"x"') AS expected_hex;
doc is {"v": "\\"x\\""}, and JSON_EXTRACT correctly represents the value as "\\"x\\"". But MatrixOne returns:
actual x
actual_hex 78
expected_hex 227822
The payload should be "x", including the two quote characters.
The same data loss occurs through all of these paths:
JSON_UNQUOTE(JSON_EXTRACT(...))JSON_EXTRACT_STRING(...)CAST(JSON_EXTRACT(...) AS CHAR)JSON_UNQUOTE(JSON_QUOTE(...))(the quote/unquote round trip is not lossless)
A read-only boundary matrix covered 8 values (ordinary string; interior, leading, trailing and paired quotes; one/two quote-only strings; paired-quote Unicode string), all 4 paths above, and 10 repetitions. It executed 320 assertions; 120 failed identically. Only values whose payload begins and ends with " fail. For example, a payload of "" becomes an empty string and "你好" becomes 你好.
Expected Behavior
JSON string conversion must preserve every character in the JSON string payload.
For the query above, expected output is:
actual "x"
actual_hex 227822
expected_hex 227822
Likewise, JSON_UNQUOTE(JSON_QUOTE(value)) must round-trip the original string, including leading/trailing quote characters.
Steps to Reproduce
Run this SQL only; no table or DML is required:
SELECT
hex(json_unquote(json_extract(
json_object('v', concat(char(34), 'x', char(34))), '$.v'
))) AS actual_hex,
hex('"x"') AS expected_hex,
hex(json_extract_string(
json_object('v', concat(char(34), 'x', char(34))), '$.v'
)) AS extract_string_hex,
hex(cast(json_extract(
json_object('v', concat(char(34), 'x', char(34))), '$.v'
) AS char)) AS cast_hex,
hex(json_unquote(json_quote(concat(char(34), 'x', char(34))))) AS roundtrip_hex;
Actual output:
actual_hex 78
expected_hex 227822
extract_string_hex 78
cast_hex 78
roundtrip_hex 78
Additional information
The deterministic 590,187-event GH Archive Kafka stream contained two affected payloads (seq 258021 and 258650), both exactly "branch_name_with_quotes". In the loaded MatrixOne table, the scalar reference column had 25 bytes while conversion from the identical JSON field had 23 bytes. This silently discarded two valid rows:
SELECT count(*) FROM github_events WHERE ref_name IS NOT NULL;
-- 446383
SELECT count(*) FROM github_events
WHERE ref_name = json_unquote(json_extract(meta, '$.ref'));
-- 446381
Source inspection points to pkg/container/bytejson/bytejson.go, ByteJson.Unquote(): it examines the first and last byte of bj.GetString() and strips them as JSON delimiters. For an extracted JSON string, GetString() is already the payload, so a payload such as "x" is incorrectly sliced to x. Existing tests cover an interior escaped quote but not a payload whose content itself has quote boundaries.
Existing-issue/PR searches covered json_unquote, json_quote, json_extract_string, ByteJson.Unquote, escaped quotes, and JSON boundary quotes. Related JSON reports concern comparison/cast behavior or missing functions; none describes loss of payload boundary quotes.
Activity
fix(json): preserve boundary quotes in unquote (#27449)
Lundomn commentedon Sep 7, 2026
QA 转测(2026-09-07)
请在本 Issue 记录实际测试版本/环境、通过或失败结论、未覆盖项及补测要求。按流程,QA 明确通过后再关闭 Issue;如发现失败或回归请保持 open 并反馈复现信息。
slyunnn commentedon Sep 8, 2026
Regression and extended verification for #27427 (2026-09-08)
Verification Environment
origin/mainatf72ca9efbeb3a7c673701e4a135cc6670c33cfde—fix(function): preserve row-local FROM_BASE64 decoding semantics (#28360).73a766720ce06589a1272b7d77c4cfa7e0e8f756—fix(json): preserve boundary quotes in unquote; it is included in the verifiedorigin/main.LOG + TN + one CN; SQL used MySQL/TCP through MOTR at CN endpoint127.0.0.1:26001.127.0.0.1:16001, CN-2127.0.0.1:16002, and Proxy127.0.0.1:6001. The issue is a local JSON conversion contract and does not require multi-CN or Proxy routing to reproduce.make buildcompleted, and focused CGo tests forpkg/container/bytejsonandpkg/sql/plan/functionpassed.What Was Covered
JSON_UNQUOTE(JSON_EXTRACT(...))reproduction with payload"x":JSON_UNQUOTE,JSON_EXTRACT_STRING,CAST(... AS CHAR), andJSON_UNQUOTE(JSON_QUOTE(...))all returned hex227822.VARCHARJSON text and binaryJSONcolumn inputs preserved ordinary text and embedded, leading, trailing, paired, one-quote, and two-quote payloads."both"and Unicode payload"你好", with every equality oracle returning1.JSON_UNQUOTE(NULL)andJSON_EXTRACT_STRING(NULL, '$.v')returnedNULL; malformed JSON producedJSON_VALID(...) = 0. The focusedTestJsonUnquoteRejectsInvalidFramedStringAndUTF8unit test also passed.JSON_UNQUOTE(JSON_QUOTE('plain'))returnedplain, and the session remained usable.cleanup_database_count = 0after each run.127.0.0.1:16001/127.0.0.1:16002, Proxy execution through127.0.0.1:6001, Kafka/GH Archive ingestion, and workload-scale validation.Findings
The fix returns decoded
TpCodeStringpayload bytes directly, so JSON string payload delimiters are no longer inferred from content. Boundary quotes are therefore retained rather than being removed byByteJson.Unquote().CHAR(34)is binary-typed in this SQL context; the directJSON_OBJECTreproduction therefore explicitly casts theCONCAT(...)payload toCHARtext. TheVARCHARand binaryJSONcolumn matrix independently proves the affected conversion contract without relying on that constructor typing detail.Large-data regression is not needed. The defect depends on JSON string payload boundaries, not row count, block/batch boundaries, memory or spill, concurrency, skew, network transfer, or resource scale. The minimal deterministic matrix covers the relevant string-content boundary.
MOTR / BVT Coverage
suites/14_issue_regression/t/issue_27427_json_unquote_boundary.testandsuites/14_issue_regression/r/issue_27427_json_unquote_boundary.result.13/13statements.test/issue-27427-json-unquote-boundary; commitb6c44ba(test: add MOTR regression for #27427), pushed by SSH.Final Conclusion
Fixed. Latest
origin/maincontains the related fix and passes the original reproduction, happy-path, boundary, Unicode/binary-JSON compatibility,NULL, malformed-input validation, cleanup, and focused unit coverage. Large-data regression is not required for the reasons above.fix(json): preserve boundary quotes in unquote (matrixorigin#27449)
fix(json): preserve boundary quotes in unquote (matrixorigin#27449)
fix(json): preserve boundary quotes in unquote (matrixorigin#27449)