Make use of StringSplitOptions.TrimEntries when possible (#18412)

This commit is contained in:
Berkan Diler
2022-10-31 22:20:22 +05:00
committed by GitHub
parent 9016adf1c2
commit 8619d8432f
2 changed files with 12 additions and 14 deletions
@@ -1273,24 +1273,23 @@ namespace System.Management.Automation
};
var modulePathList = new List<string>();
foreach (var path in currentModulePath.Split(';'))
foreach (var path in currentModulePath.Split(';', StringSplitOptions.TrimEntries))
{
var trimmedPath = path.Trim();
if (!excludeModulePaths.Contains(trimmedPath))
if (!excludeModulePaths.Contains(path))
{
// make sure this module path is Not part of other PS Core installation
var possiblePwshDir = Path.GetDirectoryName(trimmedPath);
var possiblePwshDir = Path.GetDirectoryName(path);
if (string.IsNullOrEmpty(possiblePwshDir))
{
// i.e. module dir is in the drive root
modulePathList.Add(trimmedPath);
modulePathList.Add(path);
}
else
{
if (!File.Exists(Path.Combine(possiblePwshDir, "pwsh.dll")))
{
modulePathList.Add(trimmedPath);
modulePathList.Add(path);
}
}
}