Skip to content

Fix parse_string_strict() to detect unbalanced quotes properly - #4928

Merged
sophiajt merged 1 commit into
nushell:mainfrom
uasi:fix-parse-string-strict
Mar 24, 2022
Merged

sophiajt merged 1 commit into
nushell:mainfrom
uasi:fix-parse-string-strict

Conversation

@uasi

@uasi uasi commented Mar 24, 2022 •

Copy link
Copy Markdown
Contributor

Description

Current implementation does not detect unbalanced quotes when bytes is equal to ', ", $', $", or $'anything where anything is 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 -- --check to check standard code formatting (cargo fmt --all applies these changes)
  • cargo clippy --all --all-features -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style
  • cargo build; cargo test --all --all-features to check that all the tests pass

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"\'") {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$'anything is undetected because of this bytes.starts_with(b"$\"") (should be bytes.starts_with(b"$'")).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$'anything is undetected because of this bytes.starts_with(b"$\"") (should be bytes.starts_with(b"$'")).

@uasi
uasi marked this pull request as draft March 24, 2022 10:08
@uasi
uasi force-pushed the fix-parse-string-strict branch from 30b4377 to 4dcec3b Compare March 24, 2022 10:16
@uasi
uasi marked this pull request as ready for review March 24, 2022 10:18
@sophiajt

Copy link
Copy Markdown
Contributor

thanks!

@sophiajt
sophiajt merged commit 9001329 into nushell:main Mar 24, 2022
@uasi
uasi deleted the fix-parse-string-strict branch March 24, 2022 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Single quotes string variable interpolation error when there is = in it

3 participants