Repository navigation
Description
Description
JSON_QUOTE() cannot handle ordinary UTF-8 strings containing control characters such as U+0000, U+0001, or U+001F. It builds a Go-style \\xNN escape, which is not a JSON escape sequence, then fails while parsing its own generated text.
Environment
- Branch:
main - Commit:
17c161a31b47a22e71ca222839143f66717ac365 - Deployment: local single-CN test service
- Test date: 2026-09-03
- MySQL control: isolated MySQL
8.0.45
Steps to reproduce
SELECT JSON_QUOTE(CONCAT('A', CHAR(1), 'B'));
SELECT JSON_QUOTE(CONCAT('A', CHAR(0), 'B'));
SELECT JSON_QUOTE(CONCAT('A', CHAR(31), 'B'));Actual behavior
All three statements return an invalid-JSON error. For example, CHAR(1) returns:
ERROR 20301 (HY000): invalid input: json text "A\\x01B"
The same result reproduces 3/3 times.
Expected behavior
JSON_QUOTE() should always produce a valid JSON string literal. MySQL 8.0.45 returns the following UTF-8 JSON text, shown as hex:
A + U+0000 + B -> 22415C75303030304222
A + U+0001 + B -> 22415C75303030314222
A + U+001F + B -> 22415C75303031664222
Stability and controls
- Reproducer:
3/3for U+0000, U+0001, and U+001F. - MySQL 8.0.45 control returns valid JSON strings for all three characters.
- MatrixOne control: printable text and standard newline, tab, backslash, and double-quote escapes work.
- No DDL or DML is involved.
Code analysis
pkg/sql/plan/function/func_unary.go:JsonQuote uses strconv.Quote(str). For arbitrary control bytes, Go emits \\xNN; JSON permits \\u00NN (or the standard short escapes), not \\xNN. The subsequent types.ParseStringToByteJson() therefore rejects the generated string. JSON-specific escaping must replace Go string quoting here.
Regression coverage
After the fix, add deterministic JSON_QUOTE() cases for U+0000, U+0001, U+001F, newline/tab, backslash, double quote, and a UTF-8 non-ASCII character. Verify each result is valid JSON and round-trips through JSON_UNQUOTE().
Activity
fix(json): return escaped text from JSON_QUOTE (#28091)
VioletQwQ-0 commentedon Sep 8, 2026
【QA 交接|PR #28091 已合并】
关联合并:PR #28091(merge commit 3d46ea9);当前 main=1cfec4c80134adc5640a3bbf1aef7aaa87a45282。
本次范围:JSON_QUOTE 对控制字符、UTF-8 合法性和 JSON string escaping 的兼容行为,SQL NULL 必须保持 NULL,不能退化为 binary JSON。
合并后证据:PR required checks 无失败;本地 exact-main CGo 自测因缺少 cgo/libmo.dylib 阻塞,mo-tester 未安装,未宣称本地 PASS。
请在合并版本连续复验控制字符、非 ASCII/非法 UTF-8、NULL、常量/列值和 prepared rebinding,并覆盖单 CN、多 CN、重启/读回。PASS 标准是字符串内容、字符集/排序规则和转义结果与 MySQL 8 一致;FAIL 时请保留 SQL、main SHA、重复轮次和实际/期望结果。
VioletQwQ-0 commentedon Sep 8, 2026
补充 pin:远端 main 已推进到 9f87b62。请以该当前 main 复验;此前列出的合并提交、测试范围和 PASS/FAIL 标准保持不变。该更新不代表 QA PASS。
VioletQwQ-0 commentedon Sep 8, 2026
再次补充 pin:远端 main 已推进到 9cedf6e。请以该当前 main 复验;此前列出的合并提交、测试范围和 PASS/FAIL 标准保持不变。该更新不代表 QA PASS。
VioletQwQ-0 commentedon Sep 8, 2026
Automation checkpoint: merged PR #28091 is being validated against current upstream/main 6d44c50. This issue remains open in phase/testing; no terminal tester PASS has been recorded in the current handoff. Please report complete version, environment, scoped scenario results, and terminal PASS/FAIL evidence before any closure decision.
Ariznawlll commentedon Sep 9, 2026
测试版本
mainf0c31cd4b830be32442cf329e0a3fb08aa9c16c3原问题验证
在
VARCHARUTF-8 文本域中构造A + U+0000/U+0001/U+001F + B,分别验证JSON_QUOTE的字节结果、JSON_VALID和JSON_UNQUOTE回环。三轮均得到:410042->22415C75303030304222->410042;410142->22415C75303030314222->410142;411F42->22415C75303031664222->411F42。三项
JSON_VALID均为1,不再生成旧实现的\\xNN非 JSON 转义。Happy Path 覆盖
PREPARE/EXECUTE参数路径以 U+001F 复测,结果为22415C75303031664222、JSON_VALID=1、回环411F42,连续 3 次一致。Unhappy Path 覆盖
CHAR(1)属于 binary domain,不是本 issue 的 UTF-8 text 输入;JSON_QUOTE按当前契约返回ERROR 20301: binary data not supported by json_quote。JSON_VALID(JSON_QUOTE(v))的最小/最大值均为1;失败没有污染已有文本数据。白盒验证
pkg/sql/plan/function的TestJsonQuote、TestJsonQuoteRejectsInvalidUTF8、TestJsonQuoteRejectsBinaryDomain、TestJsonQuoteReturnType在该 main 构建上-count=3通过。该覆盖分别验证文本转义、非法 UTF-8 拒绝、binary domain 拒绝和返回类型。回归测试
0f6044d006674821281b7a0c6bd485886c6c0aca。suites/14_issue_regression/t/issue_28044_json_quote_control_utf8.test。./motr --record --repeat 3 --do-test '14_issue_regression\\.issue_28044_json_quote_control_utf8' -v:3/3 用例、39/39 语句通过;非 record 相同命令再次 3/3 通过。测试证据
MOTR result 文件固定断言三种控制字符的输入/输出十六进制、JSON 有效性、反序列化回环、prepared 执行,以及 binary 拒绝后的表状态。
测试结论
测试通过。
fix(json): return escaped text from JSON_QUOTE (matrixorigin#28091)
fix(json): return escaped text from JSON_QUOTE (matrixorigin#28091)
fix(json): return escaped text from JSON_QUOTE (matrixorigin#28091)