mirror of
https://github.com/nushell/nushell.git
synced 2025-03-22 11:37:10 +01:00
Fix to nuon --serialize
of closure (#15357)
# Description Closes #15351 Adds quotes that were missed in #14698 with the proper escaping. # User-Facing Changes `to nuon --serialize` will now produce a quoted string instead of illegal nuon when given a closure # Tests + Formatting Reenable the `to nuon` rejection of closures in the base state test. Added test for quoting.
This commit is contained in:
parent
2ea2a904e8
commit
7a6cfa24fc
@ -307,7 +307,6 @@ fn from_nuon_datetime() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn to_nuon_errs_on_closure() {
|
||||
let actual = nu!(pipeline(
|
||||
r#"
|
||||
@ -316,7 +315,19 @@ fn to_nuon_errs_on_closure() {
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("can't convert closure to NUON"));
|
||||
assert!(actual.err.contains("not deserializable"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_nuon_closure_coerced_to_quoted_string() {
|
||||
let actual = nu!(pipeline(
|
||||
r#"
|
||||
{|| to nuon}
|
||||
| to nuon --serialize
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "\"{|| to nuon}\"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -99,7 +99,9 @@ fn value_to_string(
|
||||
}
|
||||
Value::Closure { val, .. } => {
|
||||
if serialize_types {
|
||||
Ok(val.coerce_into_string(engine_state, span)?.to_string())
|
||||
Ok(escape_quote_string(
|
||||
&val.coerce_into_string(engine_state, span)?,
|
||||
))
|
||||
} else {
|
||||
Err(ShellError::UnsupportedInput {
|
||||
msg: "closures are currently not deserializable (use --serialize to serialize as a string)".into(),
|
||||
|
@ -108,7 +108,7 @@ fn literal_closure() {
|
||||
|
||||
#[test]
|
||||
fn literal_closure_to_nuon() {
|
||||
test_eval("{||} | to nuon --serialize", Eq("{||}"))
|
||||
test_eval("{||} | to nuon --serialize", Eq("\"{||}\""))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user