Commit 73475ea
Fix infinite loop in Parser.with_names for malformed WITH statements (#605)
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 <noreply@anthropic.com>1 parent 1fbfee4 commit 73475ea
3 files changed
+21
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
| 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 | | |
| |||
676 | 682 | | |
677 | 683 | | |
678 | 684 | | |
679 | | - | |
| 685 | + | |
680 | 686 | | |
681 | 687 | | |
682 | 688 | | |
| |||
| 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