Enable CA1858: Use 'StartsWith' instead of 'IndexOf' (#26107)

This commit is contained in:
xtqqczze
2025-10-08 08:22:54 +05:00
committed by GitHub
parent 0ef738b36f
commit 5cdafbc4c7
5 changed files with 10 additions and 7 deletions
@@ -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),