mirror of
https://github.com/nushell/nushell.git
synced 2025-03-29 17:16:49 +01:00
Fix access to columns with quoted names (#1662)
This commit is contained in:
parent
ad7a3fd908
commit
df90d9e4b6
@ -235,3 +235,13 @@ fn errors_fetching_by_index_out_of_bounds() {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn quoted_column_access() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats",
|
||||||
|
r#"echo '[{"foo bar": {"baz": 4}}]' | from-json | get "foo bar".baz | echo $it"#
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(actual, "4");
|
||||||
|
}
|
||||||
|
@ -104,45 +104,6 @@ fn bare(src: &mut Input, span_offset: usize) -> Result<Spanned<String>, ParseErr
|
|||||||
Ok(bare.spanned(span))
|
Ok(bare.spanned(span))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn quoted(
|
|
||||||
src: &mut Input,
|
|
||||||
delimiter: char,
|
|
||||||
span_offset: usize,
|
|
||||||
) -> Result<Spanned<String>, ParseError> {
|
|
||||||
skip_whitespace(src);
|
|
||||||
|
|
||||||
let mut quoted_string = String::new();
|
|
||||||
let start_offset = if let Some((pos, _)) = src.peek() {
|
|
||||||
*pos
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
let _ = src.next();
|
|
||||||
|
|
||||||
let mut found_end = false;
|
|
||||||
|
|
||||||
for (_, c) in src {
|
|
||||||
if c != delimiter {
|
|
||||||
quoted_string.push(c);
|
|
||||||
} else {
|
|
||||||
found_end = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
quoted_string.insert(0, delimiter);
|
|
||||||
if found_end {
|
|
||||||
quoted_string.push(delimiter);
|
|
||||||
}
|
|
||||||
|
|
||||||
let span = Span::new(
|
|
||||||
start_offset + span_offset,
|
|
||||||
start_offset + span_offset + quoted_string.len(),
|
|
||||||
);
|
|
||||||
Ok(quoted_string.spanned(span))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn command(src: &mut Input, span_offset: usize) -> Result<LiteCommand, ParseError> {
|
fn command(src: &mut Input, span_offset: usize) -> Result<LiteCommand, ParseError> {
|
||||||
let command = bare(src, span_offset)?;
|
let command = bare(src, span_offset)?;
|
||||||
if command.item.is_empty() {
|
if command.item.is_empty() {
|
||||||
@ -193,12 +154,12 @@ fn pipeline(src: &mut Input, span_offset: usize) -> Result<LiteBlock, ParseError
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'"' | '\'' => {
|
// '"' | '\'' => {
|
||||||
let c = *c;
|
// let c = *c;
|
||||||
// quoted string
|
// // quoted string
|
||||||
let arg = quoted(src, c, span_offset)?;
|
// let arg = quoted(src, c, span_offset)?;
|
||||||
cmd.args.push(arg);
|
// cmd.args.push(arg);
|
||||||
}
|
// }
|
||||||
_ => {
|
_ => {
|
||||||
// basic argument
|
// basic argument
|
||||||
let arg = bare(src, span_offset)?;
|
let arg = bare(src, span_offset)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user