Repository navigation
Fix parse_string_strict() to detect unbalanced quotes properly - #4928
Merged
Merged
Conversation
uasi
commented
Mar 24, 2022
| if (bytes.starts_with(b"\"") || (bytes.starts_with(b"$\""))) && !bytes.ends_with(b"\"") { | ||
| return (garbage(span), Some(ParseError::Unclosed("\"".into(), span))); | ||
| } | ||
| if (bytes.starts_with(b"\'") || (bytes.starts_with(b"$\""))) && !bytes.ends_with(b"\'") { |
Contributor
Author
There was a problem hiding this comment.
$'anything is undetected because of this bytes.starts_with(b"$\"") (should be bytes.starts_with(b"$'")).
There was a problem hiding this comment.
$'anythingis undetected because of thisbytes.starts_with(b"$\"")(should bebytes.starts_with(b"$'")).
uasi
marked this pull request as draft
March 24, 2022 10:08
uasi
force-pushed
the
fix-parse-string-strict
branch
from
March 24, 2022 10:16
30b4377 to
4dcec3b
Compare
uasi
marked this pull request as ready for review
March 24, 2022 10:18
Contributor
|
thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Current implementation does not detect unbalanced quotes when
bytesis equal to',",$',$", or$'anythingwhereanythingis a non-empty string.This behavior causes a parse error with
let x = "=". This is because"="is interpreted as assigning the value"to the environment variable"as a result of incorrectly assuming that"is a valid string (see https://github.com/nushell/nushell/blob/0.60.0/crates/nu-parser/src/parser.rs#L4090-L4135).Fixes #4890
Tests
Make sure you've run and fixed any issues with these commands:
cargo fmt --all -- --checkto check standard code formatting (cargo fmt --allapplies these changes)cargo clippy --all --all-features -- -D warnings -D clippy::unwrap_used -A clippy::needless_collectto check that you're using the standard code stylecargo build; cargo test --all --all-featuresto check that all the tests pass