Skip to content

Commit e45a9f7

Browse files
fix: preserve PowerShell stdin functionality when adding UTF-8 encoding
- Add special case handling for '-' stdin sentinel in PowerShell commands - Prevent UTF-8 encoding prefix from breaking 'pwsh -Command -' pattern - Add comprehensive test case for stdin functionality - Addresses bot review feedback from PR #4315 Signed-off-by: Chenyang Li <[email protected]>
1 parent df6ba7b commit e45a9f7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

codex-rs/core/src/shell.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ impl Shell {
9090
if let Some(command_index) = command.iter().position(|arg| arg == "-Command") {
9191
let mut modified_command = command.clone();
9292
if let Some(cmd_arg) = modified_command.get_mut(command_index + 1) {
93+
// Special case: preserve stdin sentinel "-"
94+
if cmd_arg == "-" {
95+
// For stdin input, we can't prepend to the argument itself.
96+
// Instead, we need to handle UTF-8 encoding differently or skip it.
97+
// For now, preserve the original behavior for stdin.
98+
return Some(command);
99+
}
93100
// Prepend UTF-8 encoding setup to the command
94101
*cmd_arg = format!("[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; {}", cmd_arg);
95102
}
@@ -628,5 +635,18 @@ mod tests_windows {
628635
assert!(actual.is_some());
629636
let cmd = actual.unwrap();
630637
assert_eq!(cmd, input); // Should be unchanged
638+
639+
// Test 4: PowerShell command with stdin sentinel "-" should preserve original behavior
640+
let input = vec![
641+
"pwsh.exe".to_string(),
642+
"-NoProfile".to_string(),
643+
"-Command".to_string(),
644+
"-".to_string(),
645+
];
646+
let actual = shell.format_default_shell_invocation(input);
647+
648+
assert!(actual.is_some());
649+
let cmd = actual.unwrap();
650+
assert_eq!(cmd, input); // Should be unchanged to preserve stdin functionality
631651
}
632652
}

0 commit comments

Comments
 (0)