From 8abda7dda62ea5c09f158ccbbeba0afd4ad61ff0 Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL)" Date: Thu, 15 Nov 2018 18:19:48 -0800 Subject: [PATCH 1/2] [package] 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 | 24 +++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/assets/Product.wxs b/assets/Product.wxs index 11e91a87574..70aec2abba8 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 803750802fb..27aeb99e795 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs @@ -188,7 +188,8 @@ internal class CommandLineParameterParser "command", "settingsfile", "help", - "workingdirectory" + "workingdirectory", + "removeworkingdirectorytrailingcharacter" }; internal CommandLineParameterParser(PSHostUserInterface hostUI, string bannerText, string helpText) @@ -401,7 +402,20 @@ internal bool NonInteractive internal string WorkingDirectory { - get { return _workingDirectory; } + get + { + if (_removeWorkingDirectoryTrailingCharacter && _workingDirectory.Length > 0) + { + return _workingDirectory.Remove(_workingDirectory.Length - 1); + } + + return _workingDirectory; + } + } + + internal bool RemoveWorkingDirectoryTrailingCharacter + { + get { return _removeWorkingDirectoryTrailingCharacter; } } #endregion Internal properties @@ -934,6 +948,10 @@ private void ParseHelper(string[] args) _workingDirectory = args[i]; } + else if (MatchSwitch(switchKey, "removeworkingdirectorytrailingcharacter", "removeworkingdirectorytrailingcharacter")) + { + _removeWorkingDirectoryTrailingCharacter = true; + } else { // The first parameter we fail to recognize marks the beginning of the file string. @@ -1364,6 +1382,8 @@ private bool CollectArgs(string[] args, ref int i) private string _file; private string _executionPolicy; private string _workingDirectory; + + private bool _removeWorkingDirectoryTrailingCharacter = false; } } // namespace From ca182e9b863b4a626901cf2c9f707a3b5158c848 Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL)" Date: Fri, 16 Nov 2018 17:44:16 -0800 Subject: [PATCH 2/2] [package] address Chris' comment --- .../host/msh/CommandLineParameterParser.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs index 27aeb99e795..bb7a734723d 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs @@ -404,19 +404,22 @@ internal string 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 @@ -948,10 +951,12 @@ private void ParseHelper(string[] args) _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. @@ -1383,7 +1388,9 @@ private bool CollectArgs(string[] args, ref int i) private string _executionPolicy; private string _workingDirectory; +#if !UNIX private bool _removeWorkingDirectoryTrailingCharacter = false; +#endif } } // namespace