mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Enable CA1858: Use 'StartsWith' instead of 'IndexOf' (#26107)
This commit is contained in:
@@ -311,8 +311,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
byte[] iv = null;
|
||||
|
||||
// If this is a V2 package
|
||||
if (String.IndexOf(SecureStringHelper.SecureStringExportHeader,
|
||||
StringComparison.OrdinalIgnoreCase) == 0)
|
||||
if (String.StartsWith(SecureStringHelper.SecureStringExportHeader, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -8286,7 +8286,7 @@ namespace System.Management.Automation.Internal
|
||||
ArgumentNullException.ThrowIfNull(streamName);
|
||||
|
||||
string adjustedStreamName = streamName.Trim();
|
||||
if (adjustedStreamName.IndexOf(':') != 0)
|
||||
if (!adjustedStreamName.StartsWith(':'))
|
||||
{
|
||||
adjustedStreamName = ":" + adjustedStreamName;
|
||||
}
|
||||
|
||||
@@ -4539,7 +4539,7 @@ namespace System.Management.Automation
|
||||
}
|
||||
}
|
||||
|
||||
if (path.IndexOf(StringLiterals.HomePath, StringComparison.Ordinal) == 0)
|
||||
if (path.StartsWith(StringLiterals.HomePath, StringComparison.Ordinal))
|
||||
{
|
||||
// Support the single "~"
|
||||
if (path.Length == 1)
|
||||
@@ -4638,7 +4638,7 @@ namespace System.Management.Automation
|
||||
}
|
||||
}
|
||||
|
||||
if (path.IndexOf(StringLiterals.HomePath, StringComparison.Ordinal) == 0)
|
||||
if (path.StartsWith(StringLiterals.HomePath, StringComparison.Ordinal))
|
||||
{
|
||||
// Strip of the ~ and the \ or / if present
|
||||
|
||||
|
||||
@@ -115,8 +115,8 @@ namespace System.Management.Automation
|
||||
if (!string.IsNullOrEmpty(timeStampServerUrl))
|
||||
{
|
||||
if ((timeStampServerUrl.Length <= 7) || (
|
||||
(timeStampServerUrl.IndexOf("http://", StringComparison.OrdinalIgnoreCase) != 0) &&
|
||||
(timeStampServerUrl.IndexOf("https://", StringComparison.OrdinalIgnoreCase) != 0)))
|
||||
!timeStampServerUrl.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
|
||||
!timeStampServerUrl.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
throw PSTraceSource.NewArgumentException(
|
||||
nameof(certificate),
|
||||
|
||||
Reference in New Issue
Block a user