From fc7da1128965e4a4c7b09bfdb28aa3c6907118d5 Mon Sep 17 00:00:00 2001 From: James Truher Date: Tue, 1 Jun 2021 11:00:30 -0700 Subject: [PATCH] Change variable name to be more representative of what we're working with. Tighten up what will activate the Legacy behavior by including the directory separator for the executables. --- .../engine/NativeCommandProcessor.cs | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/System.Management.Automation/engine/NativeCommandProcessor.cs b/src/System.Management.Automation/engine/NativeCommandProcessor.cs index ea51aec6be..4522af1730 100644 --- a/src/System.Management.Automation/engine/NativeCommandProcessor.cs +++ b/src/System.Management.Automation/engine/NativeCommandProcessor.cs @@ -1267,25 +1267,30 @@ private ProcessStartInfo GetProcessStartInfo(bool redirectOutput, bool redirectE /// Determine if we have a special file which will change the way native argument passing /// is done on Windows. We use legacy behavior for cmd.exe, .bat, .cmd files. /// - /// The file to use when checking how to pass arguments. + /// The file to use when checking how to pass arguments. /// A boolean indicating what passing style should be used. - private static bool UseLegacyPassingStyle(string filename) + private static bool UseLegacyPassingStyle(string filePath) { - if (filename == null || filename == string.Empty) + if (filePath == null || filePath == string.Empty) { return false; } - string commandPath = filename.ToLowerInvariant(); + string commandPath = filePath.ToLowerInvariant(); // This is the list of files which will trigger Legacy behavior if // PSNativeCommandArgumentPassing is set to "Windows". // The following native commands have non-standard behavior with regard to argument passing. + // It's possible (but not likely) that one of the executables could have forward slashes, + // so we check for both. string[] exceptions = new string[] { - "cmd.exe", - "cscript.exe", - "wscript.exe", + "\\cmd.exe", + "/cmd.exe", + "\\cscript.exe", + "/cscript.exe", + "\\wscript.exe", + "/wscript.exe", ".bat", ".cmd", ".vbs", @@ -1294,7 +1299,7 @@ private static bool UseLegacyPassingStyle(string filename) }; foreach (string exception in exceptions) { - if (filename.EndsWith(exception)) + if (filePath.EndsWith(exception)) { return true; }