mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Make use of StringSplitOptions.TrimEntries when possible (#18412)
This commit is contained in:
+7
-8
@@ -55,35 +55,34 @@ namespace Microsoft.PowerShell.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
string[] lines = _stringData.Split('\n');
|
||||
string[] lines = _stringData.Split('\n', StringSplitOptions.TrimEntries);
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string s = line.Trim();
|
||||
|
||||
if (string.IsNullOrEmpty(s) || s[0] == '#')
|
||||
if (string.IsNullOrEmpty(line) || line[0] == '#')
|
||||
continue;
|
||||
|
||||
int index = s.IndexOf(Delimiter);
|
||||
int index = line.IndexOf(Delimiter);
|
||||
if (index <= 0)
|
||||
{
|
||||
throw PSTraceSource.NewInvalidOperationException(
|
||||
ConvertFromStringData.InvalidDataLine,
|
||||
s);
|
||||
line);
|
||||
}
|
||||
|
||||
string name = s.Substring(0, index);
|
||||
string name = line.Substring(0, index);
|
||||
name = name.Trim();
|
||||
|
||||
if (result.ContainsKey(name))
|
||||
{
|
||||
throw PSTraceSource.NewInvalidOperationException(
|
||||
ConvertFromStringData.DataItemAlreadyDefined,
|
||||
s,
|
||||
line,
|
||||
name);
|
||||
}
|
||||
|
||||
string value = s.Substring(index + 1);
|
||||
string value = line.Substring(index + 1);
|
||||
value = value.Trim();
|
||||
|
||||
value = Regex.Unescape(value);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user