Commit e4e1fbf
sql: parenthesize a LIKE pattern whose right spine would steal ESCAPE
A `[I]LIKE` pattern parses at `Like` precedence and, when an `ESCAPE`
follows, sits immediately to the left of the `ESCAPE` keyword. Only
`[I]LIKE` consumes `ESCAPE`, so a `[I]LIKE` exposed on the pattern's *right*
spine steals the outer escape as its own: `x LIKE NOT (a LIKE b) ESCAPE c`,
printed bare as `x LIKE NOT a LIKE b ESCAPE c`, binds the escape onto the
inner `a LIKE b` instead of the outer `LIKE`.
The pattern's left edge was already guarded (so its left spine doesn't
re-associate out of the `LIKE`), but the escape-stealing hazard is on the
right spine and only exists when an escape is present. Add a right-edge
guard conditioned on `escape.is_some()`. The parser never builds a pattern
that is itself a trailing escapeless `[I]LIKE` under an outer escape (it
left-nests instead), so parser-produced ASTs are unaffected and the
datadriven suites are unchanged.
This drift collides under stable-string printing (both ASTs print to the
same text), so the round-trip fuzz oracle was strengthened to compare
reparsed ASTs structurally rather than by re-printed string.
Tests: adds `like_pattern_reparenthesized_after_nested_stripped` to
`sqlparser_common.rs`.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 3f73b8a commit e4e1fbf
2 files changed
Lines changed: 62 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
311 | 317 | | |
312 | 318 | | |
313 | 319 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
940 | 940 | | |
941 | 941 | | |
942 | 942 | | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
0 commit comments