Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/System.Management.Automation/engine/CommandSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ private static CanDoPathLookupResult CanDoPathLookup(string possiblePath)
/// <summary>
/// The command name to search for.
/// </summary>
private string _commandName;
private readonly string _commandName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reviewers: this fixes a violation IDE0044: Add readonly modifier, enabled in #13880.


/// <summary>
/// Determines which command types will be globbed.
Expand Down Expand Up @@ -1536,7 +1536,6 @@ private void setupPathSearcher()
if (_canDoPathLookupResult == CanDoPathLookupResult.Yes)
{
_canDoPathLookup = true;
_commandName = _commandName.TrimEnd(Utils.Separators.PathSearchTrimEnd);

_pathSearcher =
new CommandPathSearch(
Expand All @@ -1561,7 +1560,6 @@ private void setupPathSearcher()

if (!string.IsNullOrEmpty(fileName))
{
fileName = fileName.TrimEnd(Utils.Separators.PathSearchTrimEnd);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we should have a test for this? With this we should now be able to call executables that have trailing whitespace? (although seems like a bad practice)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test what? In common, it is impossible to know what is OS and file system limitations. As .Net team concluded, the best thing we can do is to defer checks to OS and file system.

With this we should now be able to call executables that have trailing whitespace? (although seems like a bad practice)

I don't see any changes in behavior on Windows in my manual tests.
I'd expect that now we can run a file with trailing spaces.

_pathSearcher =
new CommandPathSearch(
fileName,
Expand Down Expand Up @@ -1601,7 +1599,6 @@ private void setupPathSearcher()

if (!string.IsNullOrEmpty(fileName))
{
fileName = fileName.TrimEnd(Utils.Separators.PathSearchTrimEnd);
_pathSearcher =
new CommandPathSearch(
fileName,
Expand Down
7 changes: 1 addition & 6 deletions src/System.Management.Automation/engine/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

/// <summary>
Expand Down Expand Up @@ -1541,7 +1536,7 @@ internal static bool IsComObject(object obj)

return oldMode;
}

internal static string DisplayHumanReadableFileSize(long bytes)
{
return bytes switch
Expand Down