GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: stop 0x hex literal from swallowing trailing whitespace (#2435) by fudianchn · Pull Request #2450 · JSQLParser/JSqlParser

Conversation

@fudianchn

@fudianchn fudianchn commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

What

SELECT 0xFF FROM t (any 0x-hex literal followed by whitespace/a keyword) failed to parse, while SELECT 0xFF,1 FROM t parsed fine. This makes the 0x hex literal form stop greedily consuming trailing whitespace.

Why

MySQL and other dialects accept 0x-prefixed hex literals as values/select items (#2435). Today such a literal followed by FROM or a keyword fails:

SELECT 0xFF FROM t
  -> ParseException: Encountered: <S_IDENTIFIER> / "t", at line 1, column 18

while the same literal followed by a comma parses fine — a confusing inconsistency.

Root cause

HEX_VALUE was defined as ["0"-"9","A"-"F", " "] and shared by both hex literal forms in S_HEX:

<S_HEX: ("X" ("'" ( <HEX_VALUE> )* "'" (" ")*)+ | "0x" ( <HEX_VALUE> )+ )>

The space is intentional for the X'..' form, which allows internal whitespace (e.g. X'01 bc 2a', exercised by StringValueTest#testParseInput_BYTEA). But for the 0x form, <HEX_VALUE>+ then greedily matched the trailing space and any following hex letter — so 0xFF FROM was tokenised as a single S_HEX (0xFF F), leaving ROM t, and the parser choked on t at column 18.

How

Split the shared token so each form gets the character class it needs:

  • X'..' keeps HEX_VALUE (with space — preserves X'01 bc 2a').
  • 0x.. uses a new HEX_DIGIT token (["0"-"9","A"-"F"], no space).

IGNORE_CASE = true already makes both forms match upper/lower case, so 0xff works too. HexValue itself is unchanged.

Testing

  • New HexValueTest#testHexLiteralFollowedByPrimaryKeyword: SELECT 0xFF FROM t, SELECT 0xff FROM t, SELECT 0xDEADBEEF FROM t, SELECT 0xab FROM dual — all parse to a HexValue select item.
  • Full suite: mvn test → 4647 tests, 0 failures, 0 errors (26 pre-existing skipped), including the X'01 bc 2a' regression in StringValueTest and existing InsertTest#testHexValues*.
  • checkstyle:check / pmd:check / license:check-file-header clean.

Fixes #2435

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@fudianchn
fix: stop 0x hex literal from swallowing trailing whitespace (JSQLPar…
3281659
…ser#2435)

HEX_VALUE included a space character, so the "0x" hex literal form
greedily consumed trailing whitespace and any adjacent hex letters
(e.g. the "F" of FROM). Consequently `SELECT 0xFF FROM t` failed with
"Encountered <S_IDENTIFIER> t", while `SELECT 0xFF,1 FROM t` (comma,
no space) parsed fine.

The space is only required by the X'..' form, which deliberately allows
internal whitespace (e.g. X'01 bc 2a', covered by StringValueTest).
Split the shared token: X'..' keeps HEX_VALUE (with space), while the
0x.. form uses a new space-less HEX_DIGIT token.

Signed-off-by: 付典 <[email protected]>
manticore-projects
manticore-projects requested changes Aug 7, 2026
View reviewed changes
Comment thread src/test/java/net/sf/jsqlparser/expression/HexValueTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@fudianchn
test(hex): 按要求补充解析反解析断言
255bc72
Signed-off-by: 付典 <[email protected]>
@manticore-projects
manticore-projects merged commit 18b12f1 into JSQLParser:master Aug 7, 2026
7 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@manticore-projects

manticore-projects commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Thank you much for your work and effort.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fudianchn
fudianchn deleted the fix/mysql-0x-hex-literal-2435 branch August 21, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@manticore-projects manticore-projects manticore-projects requested changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[BUG] JSQLParser 5.4-SNAPSHOT : MySQL : 0x hexadecimal literal (0xFF) not supported as select item

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@fudianchn @manticore-projects
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.