Skip to content

[Bug]: JSON_UNQUOTE rejects ordinary unquoted text #28042

Closed

Description

@Ariznawlll

Description

JSON_UNQUOTE() rejects ordinary text that is not JSON. MySQL returns non-double-quoted input unchanged; only an input that both starts and ends with a double quote and is not a valid JSON string literal should raise an error.

Environment

  • Branch: main
  • Commit: 17c161a31b47a22e71ca222839143f66717ac365
  • Deployment: local single-CN test service
  • Test date: 2026-09-03

Steps to reproduce

SELECT JSON_UNQUOTE('plain text');

Actual behavior

MatrixOne returns:

ERROR 20301 (HY000): invalid input: json text plain text

Expected behavior

MySQL returns plain text unchanged. Its documented error boundary is narrower: an error occurs only when the argument starts and ends with double quotes but is not a valid JSON string literal.

Reference: https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-unquote

Stability and controls

  • Reproducer: 3/3.
  • Controls: JSON_UNQUOTE('"abc"') returns abc; JSON_UNQUOTE('[1,2]') returns [1, 2]; JSON_UNQUOTE(NULL) returns SQL NULL in each run.
  • No DDL or DML is involved.

Code analysis

For SQL string inputs, pkg/sql/plan/function/func_unary.go:JsonUnquote calls types.ParseSliceToByteJson(v) unconditionally before ByteJson.Unquote(). That forces ordinary text through JSON-document parsing. The required behavior is to bypass parsing and return the original input when it is not framed by double quotes; retain parse/error handling for a quote-framed candidate JSON string literal.

Regression coverage

After the fix, add deterministic cases for a valid JSON string literal, an array/object text value, SQL NULL, unquoted ordinary text, and malformed quote-framed text.

Activity

  1. added
    kind/bug
    on Sep 3, 2026
  2. changed the title [-][Compatibility]: JSON_UNQUOTE rejects ordinary unquoted text[/-] [+][Bug]: JSON_UNQUOTE rejects ordinary unquoted text[/+] on Sep 3, 2026
  3. added this to the MO-202609 milestone on Sep 3, 2026
  4. added theissue type on Sep 3, 2026
  5. Ariznawlll commented on Sep 3, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充 MySQL 8.0.45 实测:

    SELECT JSON_UNQUOTE('plain text');
    -- plain text

    同一语句在 MatrixOne 当前 main 连续 3 次均返回 ERROR 20301 ... invalid input: json text plain text。

  6. added
    severity/s1
    and removed on Sep 4, 2026
  7. VioletQwQ-0 commented on Sep 11, 2026

    @VioletQwQ-0
    Collaborator

    QA handoff for merged PR #28090: #28090

    PR exact head: 64e3dbd; merge commit: 3d2e5c3. Exact-head TKE checkin run 34115028473 passed. The exact-head ALL CI UT run 34114766587 was terminated during resource-heavy tests after the runner received SIGTERM without terminal Go test events; it is not treated as a product semantic PASS or FAIL.

    请重点复测普通未加引号文本、JSON-looking 文本、外层空白/单侧引号、畸形引号、无效 UTF-8、CHAR/VARCHAR/TEXT/MEDIUMTEXT/LONGTEXT 容量与 utf8mb4_bin 元数据、CTAS,以及 DATE/TIME/numeric 和 binary 域行为。Issue 保持 OPEN,当前仅转 QA,未声明关闭。

  8. Ariznawlll commented on Sep 11, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main;官方 main 基线:4a7bfac4f91fe3e4519e25ed82654556e38d670a。
    • 实际运行构建:7013fbbd6e152ba31da2d3dbba7012ac7f8b8462,本地 2 CN、1 TN、1 Log 拓扑;修复提交 3d2e5c336ed6b6d034908cd4d2012bc9737fe958 已包含,且为上述官方 main 基线祖先。
    • 验证日期:2026-09-11。

    原问题验证

    围绕 JSON_UNQUOTE 对普通未加引号文本的兼容行为复测,确认普通文本不会被误判为 JSON 并拒绝,同时保留已定义的类型和格式错误路径。

    Happy Path 覆盖

    1. 普通文本 plain text 原样返回;合法 JSON 字符串返回 abc。
    2. JSON 数组、对象和 NULL 分别保持 [1,2]、{"a":1} 与 NULL 语义。
    3. CTAS 后结果列为 varchar/utf8mb4/utf8mb4_bin,确保输出类型可继续使用。

    Unhappy Path 覆盖

    1. 单侧引号和首尾空格文本按普通文本处理;通过长度与 HEX 确认空格未被吞掉。
    2. 非字符串参数 JSON_UNQUOTE(123) 稳定返回 20203。
    3. 完整加引号但 Unicode 转义非法的 JSON 字符串稳定返回 20301。
    4. 上述场景连续执行 3 轮,结果一致。

    白盒验证

    本 issue 的验收重点为 SQL 结果、错误码与 CTAS 元数据;无额外内部状态断言。

    回归测试

    测试证据

    • 定向 3 轮:9/9 用例成功,102/102 SQL 结果匹配。
    • 全量 14_issue_regression 运行中,本用例通过;其余 6 个既有用例的预期差异与本改动无关,未修改其基线。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugphase/testingseverity/s1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions