Quote strings containing = (#16440)

Fixes nushell/nushell#16438

## Release notes summary - What our users need to know

Previously, a record key `=` would not be quoted in `to nuon`, producing
invalid nuon output. It wasn't quoted in other string values either, but
it didn't cause problems there. Now any string containing `=` gets
quoted.
This commit is contained in:
Bruce Weirdan
2025-08-17 22:33:07 +02:00
committed by GitHub
parent 625e7154e0
commit a3b00060b4
2 changed files with 15 additions and 2 deletions

View File

@@ -515,6 +515,19 @@ fn quotes_some_strings_necessarily() {
assert_eq!(actual.out, "list<string>"); assert_eq!(actual.out, "list<string>");
} }
#[test]
fn quotes_some_strings_necessarily_in_record_keys() {
let actual = nu!(pipeline(
r#"
['=', 'a=', '=a'] | each {
{$in : 42}
} | reduce {|elt, acc| $acc | merge $elt} | to nuon | from nuon | columns | describe
"#
));
assert_eq!(actual.out, "list<string>");
}
#[test] #[test]
fn read_code_should_fail_rather_than_panic() { fn read_code_should_fail_rather_than_panic() {
let actual = nu!(cwd: "tests/fixtures/formats", pipeline( let actual = nu!(cwd: "tests/fixtures/formats", pipeline(

View File

@@ -2,12 +2,12 @@ use fancy_regex::Regex;
use std::sync::LazyLock; use std::sync::LazyLock;
// This hits, in order: // This hits, in order:
// • Any character of []:`{}#'";()|$,.!? // • Any character of []:`{}#'";()|$,.!?=
// • Any digit (\d) // • Any digit (\d)
// • Any whitespace (\s) // • Any whitespace (\s)
// • Case-insensitive sign-insensitive float "keywords" inf, infinity and nan. // • Case-insensitive sign-insensitive float "keywords" inf, infinity and nan.
static NEEDS_QUOTING_REGEX: LazyLock<Regex> = LazyLock::new(|| { static NEEDS_QUOTING_REGEX: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r#"[\[\]:`\{\}#'";\(\)\|\$,\.\d\s!?]|(?i)^[+\-]?(inf(inity)?|nan)$"#) Regex::new(r#"[\[\]:`\{\}#'";\(\)\|\$,\.\d\s!?=]|(?i)^[+\-]?(inf(inity)?|nan)$"#)
.expect("internal error: NEEDS_QUOTING_REGEX didn't compile") .expect("internal error: NEEDS_QUOTING_REGEX didn't compile")
}); });