Commit ae7c0fb
Fix infinite loop in Parser.with_names for malformed WITH statements
Resolves #556.
The parser would hang indefinitely when encountering malformed SQL with
consecutive AS keywords in WITH clauses (e.g., "WITH a AS (...) AS g").
The issue was in the with_names property loop: after processing a WITH
clause, if the next token was another AS keyword (invalid syntax), the
parser would not advance the token, causing an infinite loop.
This fix:
- Detects malformed SQL with consecutive AS keywords after WITH queries
- Raises ValueError("This query is wrong") instead of hanging
- Ensures the token always advances to prevent infinite loops
- Adds test case to verify the fix
Co-Authored-By: Claude <[email protected]>1 parent 1fbfee4 commit ae7c0fb
2 files changed
Lines changed: 19 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
447 | 447 | | |
448 | 448 | | |
449 | 449 | | |
450 | | - | |
| 450 | + | |
451 | 451 | | |
452 | 452 | | |
453 | 453 | | |
| |||
474 | 474 | | |
475 | 475 | | |
476 | 476 | | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
477 | 483 | | |
478 | 484 | | |
479 | 485 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
526 | 526 | | |
527 | 527 | | |
528 | 528 | | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
0 commit comments