apache / apache/datafusion-sqlparser-rs
A bracket-quoted identifier containing `]]` round-trips to SQL that fails to reparse
- 主要語言
- Rust
- 星號
- 3.5k
- 分支
- 772
- 平均合併
- 4 天 9 小時
- 30 天內合併 PR
- 17
描述
```rust
use sqlparser::dialect::MsSqlDialect;
use sqlparser::parser::Parser;
fn main() {
let sql = "SELECT [a]]b]";
let ast = Parser::parse_sql(&MsSqlDialect {}, sql).unwrap();
let printed = ast[0].to_string();
println!("input: {}", sql);
println!("printed: {}", printed);
let reparsed = Parser::parse_sql(&MsSqlDialect {}, &printed);
println!("reparsed: {:?}", reparsed);
}
```
```
input: SELECT [a]]b]
printed: SELECT [a]b]
reparsed: Err(ParserError("Expected: end of statement, found: ] at Line: 1, Column: 12"))
```
`[a]]b]` is a bracket-quoted identifier whose value is `a]b` (the tokenizer folds the doubled `]]` into a literal `]`). Displaying the parsed AST back to SQL writes `[a]b]` instead, and that string does not parse as the same identifier: it parses as `a` followed by leftover tokens `]b]`.
Tested on sqlparser 0.62.0.
BTW, this bug was found using [hegel](https://crates.io/crates/hegeltest). Happy to contribute the tests if you're interested.
貢獻指南
這個儲存庫沒有索引到貢獻指南
研究方向
使用 MsSqlDialect、Parser::parse_sql 和 AST to_string,透過 Rust 範例重現此問題。檢查 tokenizer 如何處理成對的方括號,以及解析後的識別碼如何顯示,然後新增一個往返回歸測試,證明 [a]]b] 會重新解析為識別碼 a]b,並執行相關測試套件。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- rust
- 領域
- databases
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 68/100