Repository navigation
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
6b304f8 to
0b863c1
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the MySQL dialect scanner/lexer to accept BMP Unicode characters in unquoted identifiers only in the token position immediately following AS, enabling Unicode SELECT aliases (e.g. Arabic/Chinese). It also strengthens identifier validation to continue rejecting invalid UTF-8, NUL, and supplementary-plane characters, with regression tests covering both valid/invalid cases and legacy error positioning in non-alias contexts.
Changes:
- Add a lexer-controlled
allowUnicodeIdentifierflag to let the scanner treat non-ASCII bytes as identifier characters only afterAS. - Validate quoted identifiers (and Unicode-enabled identifiers) to reject invalid UTF-8, NUL, and supplementary characters; propagate
LEX_ERRORthrough numeric/hex/binary-prefixed identifier paths. - Add scanner- and parser-level tests for Unicode aliases and invalid Unicode inputs, plus error-position stability checks for non-alias statements.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/sql/parsers/dialect/mysql/scanner.go | Adds Unicode-aware identifier scanning/validation helpers and threads them into identifier/number/backtick-ID scanning. |
| pkg/sql/parsers/dialect/mysql/mysql_lexer.go | Enables Unicode identifier scanning when the previously lexed token is AS. |
| pkg/sql/parsers/dialect/mysql/scanner_test.go | Adds unit tests for Unicode identifiers and invalid Unicode/UTF-8 cases at the scanner level. |
| pkg/sql/parsers/dialect/mysql/mysql_sql_test.go | Adds parser-level regression tests for valid/invalid Unicode aliases and error-position expectations. |
| // allowUnicodeIdentifier is enabled by the lexer only where the grammar | ||
| // accepts Unicode aliases. Other contexts retain the original tokenization. | ||
| allowUnicodeIdentifier bool |
| func (l *Lexer) Lex(lval *yySymType) int { | ||
| l.scanner.allowUnicodeIdentifier = l.lastToken == AS | ||
| typ, str := l.scanner.Scan() |
This PR continues the unfinished work from #25793 while preserving its original commits and authorship. Review established that current `main` already accepts the quoted Arabic and Chinese aliases reported in #25014. It also established that the parser receives raw COM_QUERY bytes without the negotiated client character set, so enforcing UTF-8/BMP rules inside the scanner would reject valid non-UTF-8 client input such as latin1 `0xE9`. The production scanner changes have therefore been removed. The final diff is deliberately test-only and records the existing compatibility contract: - quoted Arabic and Chinese aliases remain accepted; - escaped delimiters preserve Unicode contents; - raw latin1 bytes remain accepted on both the fast and escaped-delimiter paths; - raw client bytes are not reclassified by interpreting them as unconditional UTF-8. Character-set-aware identifier validation must happen after a future COM_QUERY normalization boundary has decoded `character_set_client`; this PR does not introduce that broader protocol change. Approved by: @XuPeng-SH, @gouhongshen
|
Superseded by merged PR #25879. The final takeover preserved the compatible behavior with regression coverage and removed the scanner-side charset validation that lacked COM_QUERY client-charset context. |
…igin#25879) This PR continues the unfinished work from matrixorigin#25793 while preserving its original commits and authorship. Review established that current `main` already accepts the quoted Arabic and Chinese aliases reported in matrixorigin#25014. It also established that the parser receives raw COM_QUERY bytes without the negotiated client character set, so enforcing UTF-8/BMP rules inside the scanner would reject valid non-UTF-8 client input such as latin1 `0xE9`. The production scanner changes have therefore been removed. The final diff is deliberately test-only and records the existing compatibility contract: - quoted Arabic and Chinese aliases remain accepted; - escaped delimiters preserve Unicode contents; - raw latin1 bytes remain accepted on both the fast and escaped-delimiter paths; - raw client bytes are not reclassified by interpreting them as unconditional UTF-8. Character-set-aware identifier validation must happen after a future COM_QUERY normalization boundary has decoded `character_set_client`; this PR does not introduce that broader protocol change. Approved by: @XuPeng-SH, @gouhongshen
…igin#25879) This PR continues the unfinished work from matrixorigin#25793 while preserving its original commits and authorship. Review established that current `main` already accepts the quoted Arabic and Chinese aliases reported in matrixorigin#25014. It also established that the parser receives raw COM_QUERY bytes without the negotiated client character set, so enforcing UTF-8/BMP rules inside the scanner would reject valid non-UTF-8 client input such as latin1 `0xE9`. The production scanner changes have therefore been removed. The final diff is deliberately test-only and records the existing compatibility contract: - quoted Arabic and Chinese aliases remain accepted; - escaped delimiters preserve Unicode contents; - raw latin1 bytes remain accepted on both the fast and escaped-delimiter paths; - raw client bytes are not reclassified by interpreting them as unconditional UTF-8. Character-set-aware identifier validation must happen after a future COM_QUERY normalization boundary has decoded `character_set_client`; this PR does not introduce that broader protocol change. Approved by: @XuPeng-SH, @gouhongshen
…igin#25879) This PR continues the unfinished work from matrixorigin#25793 while preserving its original commits and authorship. Review established that current `main` already accepts the quoted Arabic and Chinese aliases reported in matrixorigin#25014. It also established that the parser receives raw COM_QUERY bytes without the negotiated client character set, so enforcing UTF-8/BMP rules inside the scanner would reject valid non-UTF-8 client input such as latin1 `0xE9`. The production scanner changes have therefore been removed. The final diff is deliberately test-only and records the existing compatibility contract: - quoted Arabic and Chinese aliases remain accepted; - escaped delimiters preserve Unicode contents; - raw latin1 bytes remain accepted on both the fast and escaped-delimiter paths; - raw client bytes are not reclassified by interpreting them as unconditional UTF-8. Character-set-aware identifier validation must happen after a future COM_QUERY normalization boundary has decoded `character_set_client`; this PR does not introduce that broader protocol change. Approved by: @XuPeng-SH, @gouhongshen
What type of PR is this?
Which issue(s) this PR fixes:
issue #25014
What this PR does / why we need it:
The MySQL scanner only treated ASCII letters as the start and continuation of unquoted identifiers, so select aliases containing Arabic, Chinese, or other BMP Unicode characters failed to parse.
This change enables valid BMP Unicode identifier scanning only when the lexer is reading the token after
AS. Other grammar contexts retain their original tokenization and parser error positions. Invalid UTF-8, NUL, and supplementary characters remain rejected, including numeric, hexadecimal, and binary prefix paths.Regression coverage includes Arabic and Chinese aliases, numeric prefixes, quoted aliases, invalid UTF-8, NUL, supplementary characters, bind variables, and exact legacy errors for non-alias DDL and account paths.
Validation:
make buildgo vet ./pkg/sql/parsers/...go test -count=1 ./pkg/sql/parsers/...go test -race -count=1 -run 'TestUnicodeIdentifier|TestInvalidUnicodeIdentifiers' ./pkg/sql/parsers/dialect/mysql