apache / apache/datafusion-sqlparser-rs
A bracket-quoted identifier containing `]]` round-trips to SQL that fails to reparse
- 主要言語
- Rust
- スター
- 3.5k
- フォーク
- 772
- 平均マージ
- 4日 9時間
- マージ済み PR(30日)
- 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