mirror of
https://github.com/nushell/nushell.git
synced 2025-04-01 03:36:53 +02:00
fix select for column names with spaces (#2613)
This commit is contained in:
parent
bd015e82dc
commit
f45adecd01
@ -99,3 +99,29 @@ fn allows_if_given_unknown_column_name_is_missing() {
|
|||||||
assert_eq!(actual.out, "3");
|
assert_eq!(actual.out, "3");
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn column_names_with_spaces() {
|
||||||
|
Playground::setup("select_test_4", |dirs, sandbox| {
|
||||||
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||||
|
"test_data.csv",
|
||||||
|
r#"
|
||||||
|
first name,last name
|
||||||
|
Jonathan,Turner
|
||||||
|
Jonathan,Arns
|
||||||
|
"#,
|
||||||
|
)]);
|
||||||
|
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: dirs.test(), pipeline(
|
||||||
|
r#"
|
||||||
|
open test_data.csv
|
||||||
|
| select "last name"
|
||||||
|
| to json
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
let expected_output = r#"[{"last name":"Turner"},{"last name":"Arns"}]"#;
|
||||||
|
assert_eq!(actual.out, expected_output);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -570,21 +570,13 @@ pub fn as_string(value: &Value) -> Result<String, ShellError> {
|
|||||||
UntaggedValue::Primitive(Primitive::Int(x)) => Ok(format!("{}", x)),
|
UntaggedValue::Primitive(Primitive::Int(x)) => Ok(format!("{}", x)),
|
||||||
UntaggedValue::Primitive(Primitive::Filesize(x)) => Ok(format!("{}", x)),
|
UntaggedValue::Primitive(Primitive::Filesize(x)) => Ok(format!("{}", x)),
|
||||||
UntaggedValue::Primitive(Primitive::Path(x)) => Ok(format!("{}", x.display())),
|
UntaggedValue::Primitive(Primitive::Path(x)) => Ok(format!("{}", x.display())),
|
||||||
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => {
|
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => Ok(path
|
||||||
let joined = path
|
.iter()
|
||||||
.iter()
|
.map(|member| match &member.unspanned {
|
||||||
.map(|member| match &member.unspanned {
|
UnspannedPathMember::String(name) => name.to_string(),
|
||||||
UnspannedPathMember::String(name) => name.to_string(),
|
UnspannedPathMember::Int(n) => format!("{}", n),
|
||||||
UnspannedPathMember::Int(n) => format!("{}", n),
|
})
|
||||||
})
|
.join(".")),
|
||||||
.join(".");
|
|
||||||
|
|
||||||
if joined.contains(' ') {
|
|
||||||
Ok(format!("\"{}\"", joined))
|
|
||||||
} else {
|
|
||||||
Ok(joined)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: this should definitely be more general with better errors
|
// TODO: this should definitely be more general with better errors
|
||||||
other => Err(ShellError::labeled_error(
|
other => Err(ShellError::labeled_error(
|
||||||
|
Loading…
Reference in New Issue
Block a user