Skip to content

Commit 3b45ee7

Browse files
author
Javad
authored
Code Health | Enforcing Ordinal for StringComparison (#2068)
1 parent 8fad4a4 commit 3b45ee7

File tree

30 files changed

+113
-89
lines changed

30 files changed

+113
-89
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# editorconfig.org
2+
3+
# top-most EditorConfig file
4+
root = false
5+
6+
[*.cs]
7+
8+
# CA1310: Specify StringComparison for correctness
9+
dotnet_diagnostic.CA1310.severity = error

src/Microsoft.Data.SqlClient/netcore/src/.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ csharp_prefer_simple_using_statement = false
1313

1414
# SYSLIB0039: Type or member is obsolete
1515
dotnet_diagnostic.SYSLIB0039.severity = suggestion
16+
17+
# CA1310: Specify StringComparison for correctness
18+
dotnet_diagnostic.CA1310.severity = error

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ private void ReportSNIError(SNIProviders provider)
675675
private bool InferNamedPipesInformation()
676676
{
677677
// If we have a datasource beginning with a pipe or we have already determined that the protocol is Named Pipe
678-
if (_dataSourceAfterTrimmingProtocol.StartsWith(PipeBeginning) || _connectionProtocol == Protocol.NP)
678+
if (_dataSourceAfterTrimmingProtocol.StartsWith(PipeBeginning, StringComparison.Ordinal) || _connectionProtocol == Protocol.NP)
679679
{
680680
// If the data source is "np:servername"
681681
if (!_dataSourceAfterTrimmingProtocol.Contains(PipeBeginning))
@@ -714,7 +714,7 @@ private bool InferNamedPipesInformation()
714714
return false;
715715
}
716716

717-
if (tokensByBackSlash[4].StartsWith(NamedPipeInstanceNameHeader))
717+
if (tokensByBackSlash[4].StartsWith(NamedPipeInstanceNameHeader, StringComparison.Ordinal))
718718
{
719719
InstanceName = tokensByBackSlash[4].Substring(NamedPipeInstanceNameHeader.Length);
720720
}

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCngProvider.Windows.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ private RSACng CreateRSACngProvider(string keyPath, bool isSystemOp)
369369
/// <param name="keyIdentifier">Key identifier inside the CNG provider</param>
370370
private void GetCngProviderAndKeyId(string keyPath, bool isSystemOp, out string cngProvider, out string keyIdentifier)
371371
{
372-
int indexOfSlash = keyPath.IndexOf(@"/");
372+
int indexOfSlash = keyPath.IndexOf(@"/", StringComparison.Ordinal);
373373
if (indexOfSlash == -1)
374374
{
375375
throw SQL.InvalidCngPath(keyPath, isSystemOp);

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCspProvider.Windows.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ private RSACryptoServiceProvider CreateRSACryptoProvider(string keyPath, bool is
395395
/// <param name="keyIdentifier">output containing the key name</param>
396396
private void GetCspProviderAndKeyName(string keyPath, bool isSystemOp, out string cspProviderName, out string keyIdentifier)
397397
{
398-
int indexOfSlash = keyPath.IndexOf(@"/");
398+
int indexOfSlash = keyPath.IndexOf(@"/", StringComparison.Ordinal);
399399
if (indexOfSlash == -1)
400400
{
401401
throw SQL.InvalidCspPath(keyPath, isSystemOp);

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ internal void Connect(
434434

435435
FQDNforDNSCache = serverInfo.ResolvedServerName;
436436

437-
int commaPos = FQDNforDNSCache.IndexOf(",");
437+
int commaPos = FQDNforDNSCache.IndexOf(",", StringComparison.Ordinal);
438438
if (commaPos != -1)
439439
{
440440
FQDNforDNSCache = FQDNforDNSCache.Substring(0, commaPos);

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlTypes/SqlFileStream.Windows.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ static private string GetFullPathInternal(string path)
453453
}
454454

455455
// make sure path is not DOS device path
456-
if (!path.StartsWith(@"\\") && !System.IO.PathInternal.IsDevice(path.AsSpan()))
456+
if (!path.StartsWith(@"\\", StringComparison.Ordinal) && !System.IO.PathInternal.IsDevice(path.AsSpan()))
457457
{
458458
throw ADP.Argument(StringsHelper.GetString(Strings.SqlFileStream_InvalidPath), "path");
459459
}

src/Microsoft.Data.SqlClient/netfx/src/.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ root = false
77

88
# IDE0090: Use 'new(...)'
99
csharp_style_implicit_object_creation_when_type_is_apparent = false
10+
11+
# CA1310: Specify StringComparison for correctness
12+
dotnet_diagnostic.CA1310.severity = error

src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/DbConnectionStringCommon.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ private static bool IsValidAuthenticationMethodEnum()
373373
{
374374
for (int i = 0; i < l; i++)
375375
{
376-
if (s_supportedAuthenticationModes[i].CompareTo(names[i]) != 0)
376+
if (string.Compare(s_supportedAuthenticationModes[i], names[i], StringComparison.Ordinal) != 0)
377377
{
378378
listValid = false;
379379
}

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ActiveDirectoryAuthenticationProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public override async Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthenti
122122
// Use Connection timeout value to cancel token acquire request after certain period of time.
123123
cts.CancelAfter(parameters.ConnectionTimeout * 1000); // Convert to milliseconds
124124

125-
string scope = parameters.Resource.EndsWith(s_defaultScopeSuffix) ? parameters.Resource : parameters.Resource + s_defaultScopeSuffix;
125+
string scope = parameters.Resource.EndsWith(s_defaultScopeSuffix, StringComparison.Ordinal) ? parameters.Resource : parameters.Resource + s_defaultScopeSuffix;
126126
string[] scopes = new string[] { scope };
127127
TokenRequestContext tokenRequestContext = new(scopes);
128128

0 commit comments

Comments
 (0)