Skip to content

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

Description

@predictor2718

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions