mirror of
https://github.com/nushell/nushell.git
synced 2025-05-01 08:34:26 +02:00
Fix cell path when getting columns of non-records (#7508)
A follow-up to #7497. That change made it so that `get foo` would eliminate non-record rows; I think that was an unintentional and undesirable side-effect. Before #7497: ```bash 〉[$nothing, { item: "foo" }] | get item ╭───┬─────╮ │ 0 │ │ │ 1 │ foo │ ╰───┴─────╯ ``` After #7497: ```bash 〉[$nothing, {item: "foo"}] | get item ╭───┬─────╮ │ 0 │ foo │ ╰───┴─────╯ ``` After this PR: ```bash 〉[$nothing, { item: "foo" }] | get item ╭───┬─────╮ │ 0 │ │ │ 1 │ foo │ ╰───┴─────╯ ``` cc: @merelymyself
This commit is contained in:
parent
0826e66fe0
commit
705f12c1d9
@ -179,7 +179,7 @@ fn parses_json() {
|
|||||||
fn parses_xml() {
|
fn parses_xml() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: "tests/fixtures/formats",
|
cwd: "tests/fixtures/formats",
|
||||||
"open jonathan.xml | get rss.children.channel.children | get 0.item.children | get 0.link.children.0.0"
|
"open jonathan.xml | get rss.children.channel.children | get 0.item.children | get 3.link.children.3.0"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -715,31 +715,33 @@ impl Value {
|
|||||||
}
|
}
|
||||||
Value::List { vals, span } => {
|
Value::List { vals, span } => {
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
let mut hasvalue = false;
|
let mut found_at_least_1_value = false;
|
||||||
let mut temp: Result<Value, ShellError> = Err(ShellError::NotFound(*span));
|
|
||||||
let vals = vals.iter().filter(|v| matches!(v, Value::Record { .. }));
|
|
||||||
for val in vals {
|
for val in vals {
|
||||||
temp = val.clone().follow_cell_path(
|
// only look in records; this avoids unintentionally recursing into deeply nested tables
|
||||||
&[PathMember::String {
|
if matches!(val, Value::Record { .. }) {
|
||||||
val: column_name.clone(),
|
if let Ok(result) = val.clone().follow_cell_path(
|
||||||
span: *origin_span,
|
&[PathMember::String {
|
||||||
}],
|
val: column_name.clone(),
|
||||||
insensitive,
|
span: *origin_span,
|
||||||
);
|
}],
|
||||||
if let Ok(result) = temp.clone() {
|
insensitive,
|
||||||
hasvalue = true;
|
) {
|
||||||
output.push(result);
|
found_at_least_1_value = true;
|
||||||
|
output.push(result);
|
||||||
|
} else {
|
||||||
|
output.push(Value::Nothing { span: *span });
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
output.push(Value::Nothing { span: *span });
|
output.push(Value::Nothing { span: *span });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if hasvalue {
|
if found_at_least_1_value {
|
||||||
current = Value::List {
|
current = Value::List {
|
||||||
vals: output,
|
vals: output,
|
||||||
span: *span,
|
span: *span,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return temp;
|
return Err(ShellError::NotFound(*span));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Value::CustomValue { val, .. } => {
|
Value::CustomValue { val, .. } => {
|
||||||
|
Loading…
Reference in New Issue
Block a user