Skip to content

Commit 8ff367b

Browse files
committed
chore: adds missing string comparison
Signed-off-by: Vincent Biret <[email protected]>
1 parent 8103c20 commit 8ff367b

File tree

75 files changed

+160
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+160
-114
lines changed

src/Microsoft.OpenApi.Workbench/MainModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ internal async Task ParseDocumentAsync()
219219
{
220220
if (!string.IsNullOrWhiteSpace(_inputFile))
221221
{
222-
stream = _inputFile.StartsWith("http") ? await _httpClient.GetStreamAsync(_inputFile)
222+
stream = _inputFile.StartsWith("http", StringComparison.OrdinalIgnoreCase) ? await _httpClient.GetStreamAsync(_inputFile)
223223
: new FileStream(_inputFile, FileMode.Open);
224224
}
225225
else
@@ -241,7 +241,7 @@ internal async Task ParseDocumentAsync()
241241
};
242242
if (ResolveExternal && !string.IsNullOrWhiteSpace(_inputFile))
243243
{
244-
settings.BaseUrl = _inputFile.StartsWith("http") ? new(_inputFile)
244+
settings.BaseUrl = _inputFile.StartsWith("http", StringComparison.OrdinalIgnoreCase) ? new(_inputFile)
245245
: new("file://" + Path.GetDirectoryName(_inputFile) + "/");
246246
}
247247

src/Microsoft.OpenApi/Expressions/RuntimeExpression.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,39 @@ public static RuntimeExpression Build(string expression)
3131
{
3232
Utils.CheckArgumentNullOrEmpty(expression);
3333

34-
if (!expression.StartsWith(Prefix))
34+
if (!expression.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase))
3535
{
3636
return new CompositeExpression(expression);
3737
}
3838

3939
// $url
40-
if (expression == UrlExpression.Url)
40+
if (expression.Equals(UrlExpression.Url, StringComparison.Ordinal))
4141
{
4242
return new UrlExpression();
4343
}
4444

4545
// $method
46-
if (expression == MethodExpression.Method)
46+
if (expression.Equals(MethodExpression.Method, StringComparison.Ordinal))
4747
{
4848
return new MethodExpression();
4949
}
5050

5151
// $statusCode
52-
if (expression == StatusCodeExpression.StatusCode)
52+
if (expression.Equals(StatusCodeExpression.StatusCode, StringComparison.Ordinal))
5353
{
5454
return new StatusCodeExpression();
5555
}
5656

5757
// $request.
58-
if (expression.StartsWith(RequestExpression.Request))
58+
if (expression.StartsWith(RequestExpression.Request, StringComparison.Ordinal))
5959
{
6060
var subString = expression.Substring(RequestExpression.Request.Length);
6161
var source = SourceExpression.Build(subString);
6262
return new RequestExpression(source);
6363
}
6464

6565
// $response.
66-
if (expression.StartsWith(ResponseExpression.Response))
66+
if (expression.StartsWith(ResponseExpression.Response, StringComparison.Ordinal))
6767
{
6868
var subString = expression.Substring(ResponseExpression.Response.Length);
6969
var source = SourceExpression.Build(subString);

src/Microsoft.OpenApi/Expressions/SourceExpression.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using System;
45
using Microsoft.OpenApi.Exceptions;
56
using Microsoft.OpenApi.Properties;
67

@@ -37,27 +38,27 @@ protected SourceExpression(string value)
3738
var expressions = expression.Split('.');
3839
if (expressions.Length == 2)
3940
{
40-
if (expression.StartsWith(HeaderExpression.Header))
41+
if (expression.StartsWith(HeaderExpression.Header, StringComparison.Ordinal))
4142
{
4243
// header.
4344
return new HeaderExpression(expressions[1]);
4445
}
4546

46-
if (expression.StartsWith(QueryExpression.Query))
47+
if (expression.StartsWith(QueryExpression.Query, StringComparison.Ordinal))
4748
{
4849
// query.
4950
return new QueryExpression(expressions[1]);
5051
}
5152

52-
if (expression.StartsWith(PathExpression.Path))
53+
if (expression.StartsWith(PathExpression.Path, StringComparison.Ordinal))
5354
{
5455
// path.
5556
return new PathExpression(expressions[1]);
5657
}
5758
}
5859

5960
// body
60-
if (expression.StartsWith(BodyExpression.Body))
61+
if (expression.StartsWith(BodyExpression.Body, StringComparison.Ordinal))
6162
{
6263
var subString = expression.Substring(BodyExpression.Body.Length);
6364
if (string.IsNullOrEmpty(subString))

src/Microsoft.OpenApi/Extensions/OpenApiExtensibleExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using System;
45
using Microsoft.OpenApi.Exceptions;
56
using Microsoft.OpenApi.Interfaces;
67
using Microsoft.OpenApi.Models;
@@ -26,7 +27,7 @@ public static void AddExtension<T>(this T element, string name, IOpenApiExtensio
2627
Utils.CheckArgumentNull(element);
2728
Utils.CheckArgumentNullOrEmpty(name);
2829

29-
if (!name.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix))
30+
if (!name.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase))
3031
{
3132
throw new OpenApiException(string.Format(SRResource.ExtensionFieldNameMustBeginWithXDash, name));
3233
}

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ private static void WriteHostInfoV2(IOpenApiWriter writer, IList<OpenApiServer>?
389389
else
390390
{
391391
var relativeUrl = firstServerUrl.OriginalString;
392-
if (relativeUrl.StartsWith("//"))
392+
if (relativeUrl.StartsWith("//", StringComparison.OrdinalIgnoreCase))
393393
{
394394
var pathPosition = relativeUrl.IndexOf('/', 3);
395395
writer.WriteProperty(OpenApiConstants.Host, relativeUrl.Substring(0, pathPosition));

src/Microsoft.OpenApi/Models/OpenApiReference.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public string ReferenceV3
9595
{
9696
return Id;
9797
}
98-
if (Id.StartsWith("http"))
98+
if (Id.StartsWith("http", StringComparison.OrdinalIgnoreCase))
9999
{
100100
return Id;
101101
}
@@ -238,7 +238,7 @@ private string GetExternalReferenceV3()
238238
return ExternalResource + "#" + Id;
239239
}
240240

241-
if (Id.StartsWith("http"))
241+
if (Id.StartsWith("http", StringComparison.OrdinalIgnoreCase))
242242
{
243243
return Id;
244244
}

src/Microsoft.OpenApi/Reader/V2/OpenApiContactDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal static partial class OpenApiV2Deserializer
3232

3333
private static readonly PatternFieldMap<OpenApiContact> _contactPatternFields = new()
3434
{
35-
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
35+
{s => s.StartsWith("x-", StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
3636
};
3737

3838
public static OpenApiContact LoadContact(ParseNode node, OpenApiDocument hostDocument)

src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ internal static partial class OpenApiV2Deserializer
111111
private static readonly PatternFieldMap<OpenApiDocument> _openApiPatternFields = new()
112112
{
113113
// We have no semantics to verify X- nodes, therefore treat them as just values.
114-
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
114+
{s => s.StartsWith("x-", StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
115115
};
116116

117117
private static void MakeServers(IList<OpenApiServer> servers, ParsingContext context, RootNode rootNode)

src/Microsoft.OpenApi/Reader/V2/OpenApiExternalDocsDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal static partial class OpenApiV2Deserializer
3030
private static readonly PatternFieldMap<OpenApiExternalDocs> _externalDocsPatternFields =
3131
new()
3232
{
33-
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
33+
{s => s.StartsWith("x-", StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
3434
};
3535

3636
public static OpenApiExternalDocs LoadExternalDocs(ParseNode node, OpenApiDocument hostDocument)

src/Microsoft.OpenApi/Reader/V2/OpenApiInfoDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal static partial class OpenApiV2Deserializer
4444

4545
private static readonly PatternFieldMap<OpenApiInfo> _infoPatternFields = new()
4646
{
47-
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
47+
{s => s.StartsWith("x-", StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
4848
};
4949

5050
public static OpenApiInfo LoadInfo(ParseNode node, OpenApiDocument hostDocument)

0 commit comments

Comments
 (0)