phpmyadmin / phpmyadmin/sql-parser

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

Open
#649 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
485
Forks
119
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the Lexer's number-parsing state machine, especially states 7-9 that handle b'...' literals, and compare them with how x is currently matched as a keyword. Re-run the provided Parser reproduction and confirm that the built CREATE TABLE statement preserves DEFAULT x'...' rather than producing x AS followed by a string.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, sql
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.