Fix && quotation in to nuon after proptest fail (#7564)

`proptest` caught a failing test condition for `&&` as a literal string. It requires a quotation to be parsed correctly by current `from nuon`
    
https://github.com/nushell/nushell/actions/runs/3753242377/jobs/6376308675

The change in the parser that now returns an error was introduced by https://github.com/nushell/nushell/pull/7241

This in theory doesn't have to be an error (it is a diagnostic for nushell code) but it is probably better safe than sorry to require quotation here.

- Add a test for `&&` in `to nuon` from proptest fail
- Fix `to nuon` generating invalid `&&` literal
- Add a test for `,` in `to nuon`/`from nuon` cycle
  - Bonus: should already be properly quoted
This commit is contained in:
Stefan Holderbach 2022-12-22 00:36:07 +01:00 committed by GitHub
parent 05e07ddf5c
commit ec08e4bc6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -215,7 +215,11 @@ static NEEDS_QUOTES_REGEX: Lazy<Regex> = Lazy::new(|| {
fn needs_quotes(string: &str) -> bool { fn needs_quotes(string: &str) -> bool {
// These are case-sensitive keywords // These are case-sensitive keywords
match string { match string {
"true" | "false" | "null" => return true, // `true`/`false`/`null` are active keywords in JSON and NUON
// `&&` is denied by the nu parser for diagnostics reasons
// (https://github.com/nushell/nushell/pull/7241)
// TODO: remove the extra check in the nuon codepath
"true" | "false" | "null" | "&&" => return true,
_ => (), _ => (),
}; };
// All other cases are handled here // All other cases are handled here

View File

@ -330,7 +330,9 @@ fn quotes_some_strings_necessarily() {
'-11.0..-15.0', '11.0..-15.0', '-11.0..15.0', '-11.0..-15.0', '11.0..-15.0', '-11.0..15.0',
'-11.0..<-15.0', '11.0..<-15.0', '-11.0..<15.0', '-11.0..<-15.0', '11.0..<-15.0', '-11.0..<15.0',
'-11.0..', '11.0..', '..15.0', '..-15.0', '..<15.0', '..<-15.0', '-11.0..', '11.0..', '..15.0', '..-15.0', '..<15.0', '..<-15.0',
'2000-01-01', '2022-02-02T14:30:00', '2022-02-02T14:30:00+05:00' '2000-01-01', '2022-02-02T14:30:00', '2022-02-02T14:30:00+05:00',
',',
'&&'
] | to nuon | from nuon | describe ] | to nuon | from nuon | describe
"# "#
)); ));