mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
Fix multi-line input w/ redirected stdin (#2090)
The input loop reading from stdin did not handle multi-line input correctly because it was adding a newline character where none was expected. The fix was to not include the final newline character to accept input, just like Console.ReadLine or PSReadline would.
This commit is contained in:
1 parent
22aac12c3e
commit
cf18010ad5
2 files changed
+22
-8
No files matched your search
@@ -1557,6 +1557,7 @@ namespace Microsoft.PowerShell
|
||||
if (initialContent != null)
|
||||
{
|
||||
sb.Append(initialContent);
|
||||
sb.Append('\n');
|
||||
}
|
||||
|
||||
while (true)
|
||||
@@ -1579,7 +1580,11 @@ namespace Microsoft.PowerShell
|
||||
if (!NoPrompt) Console.Out.Write('\n');
|
||||
Console.In.Read();
|
||||
}
|
||||
sb.Append('\n');
|
||||
break;
|
||||
}
|
||||
|
||||
if (c == '\n')
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1591,12 +1596,6 @@ namespace Microsoft.PowerShell
|
||||
{
|
||||
sb.Append(c);
|
||||
}
|
||||
|
||||
|
||||
if (c == '\n')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
|
||||
@@ -263,8 +263,23 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
|
||||
$si = NewProcessStartInfo "-noprofile -" -RedirectStdIn
|
||||
$process = RunPowerShell $si
|
||||
$process.StandardInput.Write("1+1`n")
|
||||
$process.StandardOutput.ReadLine() | Should Be "2"
|
||||
|
||||
# Multi-line input
|
||||
$process.StandardInput.Write("if (1)`n{`n 42`n}`n`n")
|
||||
$process.StandardOutput.ReadLine() | Should Be "42"
|
||||
$process.StandardInput.Write(@"
|
||||
function foo
|
||||
{
|
||||
'in foo'
|
||||
}
|
||||
|
||||
foo
|
||||
|
||||
"@)
|
||||
$process.StandardOutput.ReadLine() | Should Be "in foo"
|
||||
|
||||
$process.StandardInput.Close()
|
||||
$process.StandardOutput.ReadToEnd() | Should Be "2${nl}"
|
||||
EnsureChildHasExited $process
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user