Fix pipe redirection into complete (#12818)

# Description
Fixes #12796 where a combined out and err pipe redirection (`o+e>|`)
into `complete` still provides separate `stdout` and `stderr` columns in
the record. Now, the combined output will be in the `stdout` column.
This PR also fixes a similar error with the `e>|` pipe redirection.

# Tests + Formatting
Added two tests.
This commit is contained in:
Ian Manske 2024-05-11 15:32:00 +00:00 committed by GitHub
parent b9a7faad5a
commit cab86f49c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 5 deletions

View File

@ -92,3 +92,16 @@ fn capture_error_with_both_stdout_stderr_messages_not_hang_nushell() {
},
)
}
#[test]
fn combined_pipe_redirection() {
let actual = nu!("$env.FOO = hello; $env.BAR = world; nu --testbin echo_env_mixed out-err FOO BAR o+e>| complete | get stdout");
assert_eq!(actual.out, "helloworld");
}
#[test]
fn err_pipe_redirection() {
let actual =
nu!("$env.FOO = hello; nu --testbin echo_env_stderr FOO e>| complete | get stdout");
assert_eq!(actual.out, "hello");
}

View File

@ -340,7 +340,13 @@ fn eval_redirection<D: DebugContext>(
}
Ok(Redirection::file(options.create(true).open(path)?))
}
RedirectionTarget::Pipe { .. } => Ok(Redirection::Pipe(next_out.unwrap_or(OutDest::Pipe))),
RedirectionTarget::Pipe { .. } => {
let dest = match next_out {
None | Some(OutDest::Capture) => OutDest::Pipe,
Some(next) => next,
};
Ok(Redirection::Pipe(dest))
}
}
}
@ -367,11 +373,12 @@ fn eval_element_redirection<D: DebugContext>(
} => {
let stderr = eval_redirection::<D>(engine_state, stack, target, None)?;
if matches!(stderr, Redirection::Pipe(OutDest::Pipe)) {
let dest = match next_out {
None | Some(OutDest::Capture) => OutDest::Pipe,
Some(next) => next,
};
// e>| redirection, don't override current stack `stdout`
Ok((
None,
Some(next_out.map(Redirection::Pipe).unwrap_or(stderr)),
))
Ok((None, Some(Redirection::Pipe(dest))))
} else {
Ok((next_out.map(Redirection::Pipe), Some(stderr)))
}