diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs
index cf798ddabbd..15a463582f6 100644
--- a/src/System.Management.Automation/engine/CommandSearcher.cs
+++ b/src/System.Management.Automation/engine/CommandSearcher.cs
@@ -1473,7 +1473,7 @@ private static CanDoPathLookupResult CanDoPathLookup(string possiblePath)
///
/// The command name to search for.
///
- private string _commandName;
+ private readonly string _commandName;
///
/// Determines which command types will be globbed.
@@ -1536,7 +1536,6 @@ private void setupPathSearcher()
if (_canDoPathLookupResult == CanDoPathLookupResult.Yes)
{
_canDoPathLookup = true;
- _commandName = _commandName.TrimEnd(Utils.Separators.PathSearchTrimEnd);
_pathSearcher =
new CommandPathSearch(
@@ -1561,7 +1560,6 @@ private void setupPathSearcher()
if (!string.IsNullOrEmpty(fileName))
{
- fileName = fileName.TrimEnd(Utils.Separators.PathSearchTrimEnd);
_pathSearcher =
new CommandPathSearch(
fileName,
@@ -1601,7 +1599,6 @@ private void setupPathSearcher()
if (!string.IsNullOrEmpty(fileName))
{
- fileName = fileName.TrimEnd(Utils.Separators.PathSearchTrimEnd);
_pathSearcher =
new CommandPathSearch(
fileName,
diff --git a/src/System.Management.Automation/engine/Utils.cs b/src/System.Management.Automation/engine/Utils.cs
index 6cb51a4ae82..312a5260f26 100644
--- a/src/System.Management.Automation/engine/Utils.cs
+++ b/src/System.Management.Automation/engine/Utils.cs
@@ -1470,11 +1470,6 @@ internal static class Separators
internal static readonly char[] SpaceOrTab = new char[] { ' ', '\t' };
internal static readonly char[] Newline = new char[] { '\n' };
internal static readonly char[] CrLf = new char[] { '\r', '\n' };
-
- // (Copied from System.IO.Path so we can call TrimEnd in the same way that Directory.EnumerateFiles would on the search patterns).
- // Trim trailing white spaces, tabs etc but don't be aggressive in removing everything that has UnicodeCategory of trailing space.
- // String.WhitespaceChars will trim aggressively than what the underlying FS does (for ex, NTFS, FAT).
- internal static readonly char[] PathSearchTrimEnd = { (char)0x9, (char)0xA, (char)0xB, (char)0xC, (char)0xD, (char)0x20, (char)0x85, (char)0xA0 };
}
///
@@ -1541,7 +1536,7 @@ internal static bool IsComObject(object obj)
return oldMode;
}
-
+
internal static string DisplayHumanReadableFileSize(long bytes)
{
return bytes switch