fix(parser): empty span of unbalanced delimiter#16292
fix(parser): empty span of unbalanced delimiter#16292sholderbach merged 3 commits intonushell:mainfrom
Conversation
|
To illustrate what happens for The check of nushell/crates/nu-parser/src/parser.rs Lines 6220 to 6224 in 2e4900f depends on the off-by-1 nushell/crates/nu-parser/src/lex.rs Lines 499 to 506 in 2e4900f Which is the consequence of lexing nushell/crates/nu-parser/src/parser.rs Lines 6193 to 6211 in 2e4900f I suppose the ideal way to solve this issue is to fix the |
| unclosed = false; | ||
| break; | ||
| if let Some(ParseError::Unbalanced(left, right, _)) = lex_state.error.as_ref() { | ||
| if left == "{" && right == "}" { |
There was a problem hiding this comment.
I do see another place in the parser that checks both left and right before determining if the error is for unbalanced curly braces, but there's currently no situation where left would be "{" but right would be "]" or something. Feels kinda weird to use two separate strings rather than an enum or something, but I guess it doesn't matter that much, and it's out of scope for this PR anyway.
There was a problem hiding this comment.
This looks good to me, thanks for being brave enough to plunge into the parser.
I suppose the ideal way to solve this issue is to fix the
spanargument passed in fromparse_brace_exprso that trailing/is not included in the first place.
That would be nice, but probably a harder change to make. I like how simple this PR is, much easier to review.
sholderbach
left a comment
There was a problem hiding this comment.
Can you merge in main with #16231 so we can run the parse_with_keywords fuzz target on that for a bit?
Sure, actually I've noticed several unexpected consequences of this fix, running fuzz tests would be a good practice. |
|
If you want to give it a go you can find it at https://github.com/nushell/nushell/tree/main/crates/nu-parser/fuzz The basic setup would be # cargo install cargo-fuzz
cd crates/nu-parser/fuzz
mkdir out
./gather_seeds.nu
cargo fuzz run parse_with_keywords out seedsI typically run it with some additional flags to the fuzzer:
|
|
#16355 has brought another fix for things found by the fuzzer onto main, so worth rebasing onto that to run it with arbitrary bytes and not just ASCII |
|
Dang found another one of the Reduced to: |
Should be fixed now.
Rebased, but I have trouble running cargo-fuzz: Probably because my rust toolchain is not managed by rustup |
|
@sholderbach Found a new one #16586 near That doesn't necessarily mean this PR won't cause new issues because the random seed of the fuzzer is not fixed? |
Fixes #16284
Description
#15246 happens to rely on the lexer's bug to work.
Changed to a workaround solution in this PR, not sure that's good enough in terms of perf and accuracy.
@ysthakur Please take your time to review the changes of
parse_recordwith care.User-Facing Changes
Tests + Formatting
+1
After Submitting