From 019b44b1cae985cf5e0b4288d482b4ebcd3ad8a4 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 21 Apr 2016 16:03:58 -0700 Subject: [PATCH 1/2] Add test for -EncodedCommand --- test/powershell/CoreConsoleHost.Tests.ps1 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/powershell/CoreConsoleHost.Tests.ps1 b/test/powershell/CoreConsoleHost.Tests.ps1 index f2c3d48f1..4d57be5ed 100644 --- a/test/powershell/CoreConsoleHost.Tests.ps1 +++ b/test/powershell/CoreConsoleHost.Tests.ps1 @@ -8,5 +8,14 @@ Describe "CoreConsoleHost unit tests" { & $powershell -noprofile $x | ?{ $_ -match "usage: powershell" } | Should Not BeNullOrEmpty } } + + It "Should accept a Base64 encoded command" { + $commandString = "Get-Location" + $encodedCommand = [System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($commandString)) + # We don't compare to `Get-Location` directly because object and formatted output comparisons are difficult + $expected = & $powershell -noprofile -command $commandString + $actual = & $powershell -noprofile -EncodedCommand $encodedCommand + $actual | Should Be $expected + } } } From 5fee08a09784aa4db32099211d5b2840166e14f5 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 21 Apr 2016 16:05:53 -0700 Subject: [PATCH 2/2] Fix -EncodedCommand implementation PowerShell uses Encoding.Unicode, which is different from Encoding.UTF8. --- src/Microsoft.PowerShell.CoreConsoleHost/main.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.CoreConsoleHost/main.cs b/src/Microsoft.PowerShell.CoreConsoleHost/main.cs index fc80add9d..300cd25b4 100644 --- a/src/Microsoft.PowerShell.CoreConsoleHost/main.cs +++ b/src/Microsoft.PowerShell.CoreConsoleHost/main.cs @@ -146,7 +146,7 @@ OPTIONS break; case Options.EncodedCommand: byte[] data = Convert.FromBase64String(nextArg); - initialScript = Encoding.UTF8.GetString(data); + initialScript = Encoding.Unicode.GetString(data); ++i; break; default: