Hex string literal x'...' incorrectly parsed as keyword + string

未關閉
#649 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
70/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
冷清
技術堆疊
php, sql
領域
tooling

研究方向

從 Lexer 的數字解析狀態機著手,尤其關注處理 b'...' 字面值的狀態 7-9,並將其與目前將 x 比對為關鍵字的方式進行比較。重新執行提供的 Parser 重現,並確認產生的 CREATE TABLE 陳述式保留 DEFAULT x'...',而不是產生 x AS 後接一個字串。

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
PHP
星號
485
分支
119
PR 合併指標
30 天內沒有已合併 PR

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

phpmyadmin/sql-parser 的其他 Issue

查看 phpmyadmin/sql-parser 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。