From b7daa796a33ef9d20e2e60648205ee49505a0f97 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Mon, 19 Nov 2018 11:12:40 -0800 Subject: [PATCH] Enable `Open Here` context menu on Windows to work with root of a drive (#8287) support being started by Windows Shell (Open Here) where a trailing slash followed by a quote is handled incorrectly --- assets/Product.wxs | 4 +-- .../host/msh/CommandLineParameterParser.cs | 31 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/assets/Product.wxs b/assets/Product.wxs index 11e91a8757..70aec2abba 100644 --- a/assets/Product.wxs +++ b/assets/Product.wxs @@ -207,7 +207,7 @@ - + @@ -215,7 +215,7 @@ - + diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs index 803750802f..bb7a734723 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs @@ -188,7 +188,8 @@ namespace Microsoft.PowerShell "command", "settingsfile", "help", - "workingdirectory" + "workingdirectory", + "removeworkingdirectorytrailingcharacter" }; internal CommandLineParameterParser(PSHostUserInterface hostUI, string bannerText, string helpText) @@ -401,9 +402,25 @@ namespace Microsoft.PowerShell internal string WorkingDirectory { - get { return _workingDirectory; } + get + { +#if !UNIX + if (_removeWorkingDirectoryTrailingCharacter && _workingDirectory.Length > 0) + { + return _workingDirectory.Remove(_workingDirectory.Length - 1); + } + #endif + return _workingDirectory; + } } +#if !UNIX + internal bool RemoveWorkingDirectoryTrailingCharacter + { + get { return _removeWorkingDirectoryTrailingCharacter; } + } +#endif + #endregion Internal properties #region static methods @@ -934,6 +951,12 @@ namespace Microsoft.PowerShell _workingDirectory = args[i]; } +#if !UNIX + else if (MatchSwitch(switchKey, "removeworkingdirectorytrailingcharacter", "removeworkingdirectorytrailingcharacter")) + { + _removeWorkingDirectoryTrailingCharacter = true; + } +#endif else { // The first parameter we fail to recognize marks the beginning of the file string. @@ -1364,6 +1387,10 @@ namespace Microsoft.PowerShell private string _file; private string _executionPolicy; private string _workingDirectory; + +#if !UNIX + private bool _removeWorkingDirectoryTrailingCharacter = false; +#endif } } // namespace