phpmyadmin / phpmyadmin/sql-parser
Hex string literal x'...' incorrectly parsed as keyword + string
还没有人认领这个 Issue。
- 主要语言
- PHP
- 星标
- 485
- 派生
- 119
- PR 合并指标
- 30 天内没有已合并 PR
描述
Bug
The lexer incorrectly tokenizes hex string literals x'...' as two separate tokens (keyword x + string '...'),
causing the builder to produce invalid SQL x AS '...' instead of x'...'.
This affects CREATE TABLE statements with binary column defaults on MariaDB 11.8+ which outputs DEFAULT x'...'
in SHOW CREATE TABLE.
The b'...' binary string literal format is handled correctly — only x'...' is affected.
To Reproduce
$parser = new Parser("CREATE TABLE test (IP binary(16) NOT NULL DEFAULT x'00000000000000000000000000000000')");
echo $parser->statements[0]->build();
// Output: ... DEFAULT x AS `00000000000000000000000000000000`
// Expected: ... DEFAULT x'00000000000000000000000000000000'
Affected versions
Both 5.11.x and master.
Root cause
The Lexer's number parsing state machine has states 7-9 for b'...' binary literals, but no equivalent states for
x'...' hex string literals. The x is instead matched as a keyword.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Lexer 的数字解析状态机入手,尤其关注处理 b'...' 字面量的状态 7-9,并将其与当前将 x 匹配为关键字的方式进行比较。重新运行提供的 Parser 复现,并确认生成的 CREATE TABLE 语句保留 DEFAULT x'...',而不是生成 x AS 后跟一个字符串。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- php, sql
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 70/100