fix: PG parser fails on LIKE ? ESCAPE '\\' generated by JPA#6627
Open
daguimu wants to merge 1 commit intoalibaba:masterfrom
Open
fix: PG parser fails on LIKE ? ESCAPE '\\' generated by JPA#6627daguimu wants to merge 1 commit intoalibaba:masterfrom
daguimu wants to merge 1 commit intoalibaba:masterfrom
Conversation
Remove PGLexer.scanString() override that incorrectly treated backslash as an escape character inside string literals. In standard PostgreSQL (standard_conforming_strings = on, default since PG 9.1), backslash is a regular character in string literals. The old behavior caused '\' to be parsed as an escaped quote instead of a string containing backslash, breaking LIKE ? ESCAPE '\' syntax generated by Spring Data JPA. Also updates test resource file to use standard SQL '' quote escaping instead of deprecated \' escaping. Fixes alibaba#6413 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
PostgreSQL SQL parser fails when parsing
LIKE ? ESCAPE '\'syntax generated by Spring Data JPA/HibernateContainingqueries. TheWallFilterthrowsParserException: ERRORbecause the PG lexer incorrectly treats\as an escape character inside string literals.Reproduction SQL:
Root cause:
PGLexer.scanString()overrode the baseLexer.scanString()to treat\as an escape character. When encountering'\', the lexer interprets\'as an escaped quote, so the string literal never terminates — it consumes the rest of the SQL and produces an ERROR token.In standard PostgreSQL (
standard_conforming_strings = on, default since PostgreSQL 9.1 / 2011), backslash is not an escape character in regular string literals. Only E-prefixed strings (E'\\') use backslash escaping.Fix
scanString()override fromPGLexer, so it uses the baseLexer.scanString()which treats\as a regular characterLITERAL_CHARSimportpostgresql/0.txt) that used deprecated\'quote escaping to use standard SQL''escapingTests Added
9 new test cases in
Issue6413.java:test_like_escape_backslash— exact SQL from bug report (JPA-generated)test_like_escape_backslash_simple— minimal reproductiontest_like_escape_non_backslash_still_works— other escape chars (#,!,~)test_string_with_backslash_in_pg— standard PG string containing\test_string_with_double_backslash_in_pg— string containing\\test_like_escape_backslash_with_wall_filter— verifies WallFilter path (original failure)test_not_like_escape_backslash— NOT LIKE varianttest_ilike_with_backslash_string— PG-specific ILIKEtest_pg_double_single_quote_still_works— standard''escape still worksAll tests run against
postgresql,greenplum, andedbdialects where applicable.Impact
ESCAPE '\'standard_conforming_strings = onFixes #6413