From 7ca9be1428baa453064f4b8b0ccd149ac39b1ceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Mon, 24 Oct 2022 13:53:42 +0200 Subject: [PATCH] Reference PolySharp and replace Substring() calls by the range syntax --- Directory.Build.props | 9 ++++++ ...OpenIddictClientWebIntegrationGenerator.cs | 4 +-- .../OpenIddict.Sandbox.AspNet.Client.csproj | 1 + .../OpenIddict.Sandbox.AspNet.Server.csproj | 1 + .../OpenIddictClientOwinHandlers.cs | 16 +++++----- .../OpenIddictClientConfiguration.cs | 7 ++-- .../OpenIddictClientHandlers.Protection.cs | 2 +- .../Managers/OpenIddictApplicationManager.cs | 4 +-- .../OpenIddict.EntityFramework.Models.csproj | 1 + ...enIddict.EntityFrameworkCore.Models.csproj | 1 + .../OpenIddict.MongoDb.Models.csproj | 1 + .../OpenIddictServerAspNetCoreHandlers.cs | 8 ++--- .../OpenIddictServerOwinHandlers.cs | 32 +++++++++---------- .../OpenIddictServerConfiguration.cs | 4 +-- ...OpenIddictServerHandlers.Authentication.cs | 4 +-- .../OpenIddictServerHandlers.Discovery.cs | 2 +- .../OpenIddictServerHandlers.cs | 2 +- .../OpenIddictValidationAspNetCoreHandlers.cs | 2 +- .../OpenIddictValidationOwinHandlers.cs | 10 +++--- .../OpenIddictValidationConfiguration.cs | 3 +- ...OpenIddictValidationHandlers.Protection.cs | 2 +- .../OpenIddictServerIntegrationTestClient.cs | 4 +-- ...enIddictValidationIntegrationTestClient.cs | 4 +-- 23 files changed, 67 insertions(+), 57 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 4afdb32c..deb1a75f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -64,6 +64,15 @@ false + + + + + diff --git a/gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs b/gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs index 8a2a228e..3245ff2d 100644 --- a/gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs +++ b/gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs @@ -346,7 +346,7 @@ public partial class OpenIddictClientWebIntegrationBuilder Collection = (bool?) setting.Attribute("Collection") ?? false, Description = (string) setting.Attribute("Description") is string description ? - char.ToLower(description[0], CultureInfo.GetCultureInfo("en-US")) + description.Substring(1) : null, + char.ToLower(description[0], CultureInfo.GetCultureInfo("en-US")) + description[1..] : null, ClrType = (string) setting.Attribute("Type") switch { "EncryptionKey" when (string) setting.Element("EncryptionAlgorithm").Attribute("Value") @@ -875,7 +875,7 @@ public partial class OpenIddictClientWebIntegrationOptions Collection = (bool?) setting.Attribute("Collection") ?? false, Description = (string) setting.Attribute("Description") is string description ? - char.ToLower(description[0], CultureInfo.GetCultureInfo("en-US")) + description.Substring(1) : null, + char.ToLower(description[0], CultureInfo.GetCultureInfo("en-US")) + description[1..] : null, ClrType = (string) setting.Attribute("Type") switch { "EncryptionKey" when (string) setting.Element("EncryptionAlgorithm").Attribute("Value") diff --git a/sandbox/OpenIddict.Sandbox.AspNet.Client/OpenIddict.Sandbox.AspNet.Client.csproj b/sandbox/OpenIddict.Sandbox.AspNet.Client/OpenIddict.Sandbox.AspNet.Client.csproj index 11172833..6bbb6812 100644 --- a/sandbox/OpenIddict.Sandbox.AspNet.Client/OpenIddict.Sandbox.AspNet.Client.csproj +++ b/sandbox/OpenIddict.Sandbox.AspNet.Client/OpenIddict.Sandbox.AspNet.Client.csproj @@ -8,6 +8,7 @@ false disable CA3147 + true diff --git a/sandbox/OpenIddict.Sandbox.AspNet.Server/OpenIddict.Sandbox.AspNet.Server.csproj b/sandbox/OpenIddict.Sandbox.AspNet.Server/OpenIddict.Sandbox.AspNet.Server.csproj index c8011677..ef09766b 100644 --- a/sandbox/OpenIddict.Sandbox.AspNet.Server/OpenIddict.Sandbox.AspNet.Server.csproj +++ b/sandbox/OpenIddict.Sandbox.AspNet.Server/OpenIddict.Sandbox.AspNet.Server.csproj @@ -8,6 +8,7 @@ false disable CA3147 + true diff --git a/src/OpenIddict.Client.Owin/OpenIddictClientOwinHandlers.cs b/src/OpenIddict.Client.Owin/OpenIddictClientOwinHandlers.cs index 4ece2246..7a7cb931 100644 --- a/src/OpenIddict.Client.Owin/OpenIddictClientOwinHandlers.cs +++ b/src/OpenIddict.Client.Owin/OpenIddictClientOwinHandlers.cs @@ -506,22 +506,22 @@ public static partial class OpenIddictClientOwinHandlers { // If the property ends with #string, represent it as a string parameter. string key when key.EndsWith(PropertyTypes.String, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.String.Length), + Name: key[..^PropertyTypes.String.Length], Value: new OpenIddictParameter(property.Value)), // If the property ends with #boolean, return it as a boolean parameter. string key when key.EndsWith(PropertyTypes.Boolean, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Boolean.Length), + Name: key[..^PropertyTypes.Boolean.Length], Value: new OpenIddictParameter(bool.Parse(property.Value))), // If the property ends with #integer, return it as an integer parameter. string key when key.EndsWith(PropertyTypes.Integer, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Integer.Length), + Name: key[..^PropertyTypes.Integer.Length], Value: new OpenIddictParameter(long.Parse(property.Value, CultureInfo.InvariantCulture))), // If the property ends with #json, return it as a JSON parameter. string key when key.EndsWith(PropertyTypes.Json, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Json.Length), + Name: key[..^PropertyTypes.Json.Length], Value: new OpenIddictParameter(JsonSerializer.Deserialize(property.Value))), _ => default @@ -706,22 +706,22 @@ public static partial class OpenIddictClientOwinHandlers { // If the property ends with #string, represent it as a string parameter. string key when key.EndsWith(PropertyTypes.String, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.String.Length), + Name: key[..^PropertyTypes.String.Length], Value: new OpenIddictParameter(property.Value)), // If the property ends with #boolean, return it as a boolean parameter. string key when key.EndsWith(PropertyTypes.Boolean, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Boolean.Length), + Name: key[..^PropertyTypes.Boolean.Length], Value: new OpenIddictParameter(bool.Parse(property.Value))), // If the property ends with #integer, return it as an integer parameter. string key when key.EndsWith(PropertyTypes.Integer, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Integer.Length), + Name: key[..^PropertyTypes.Integer.Length], Value: new OpenIddictParameter(long.Parse(property.Value, CultureInfo.InvariantCulture))), // If the property ends with #json, return it as a JSON parameter. string key when key.EndsWith(PropertyTypes.Json, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Json.Length), + Name: key[..^PropertyTypes.Json.Length], Value: new OpenIddictParameter(JsonSerializer.Deserialize(property.Value))), _ => default diff --git a/src/OpenIddict.Client/OpenIddictClientConfiguration.cs b/src/OpenIddict.Client/OpenIddictClientConfiguration.cs index ef841b56..26cdbe1c 100644 --- a/src/OpenIddict.Client/OpenIddictClientConfiguration.cs +++ b/src/OpenIddict.Client/OpenIddictClientConfiguration.cs @@ -82,8 +82,7 @@ public class OpenIddictClientConfiguration : IPostConfigureOptions new[] { issuer.AbsoluteUri, // Uri.AbsoluteUri is normalized and always contains a trailing slash. - issuer.AbsoluteUri.Substring(0, issuer.AbsoluteUri.Length - 1) + issuer.AbsoluteUri[..^1] }, Uri issuer => new[] { issuer.AbsoluteUri } diff --git a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs index d072cea2..408033c8 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs @@ -1433,10 +1433,10 @@ public class OpenIddictApplicationManager : IOpenIddictApplication BinaryPrimitives.WriteUInt32BigEndian(payload.Slice(9, 12), (uint) salt.Length); // Write the salt. - salt.CopyTo(payload.Slice(13)); + salt.CopyTo(payload[13..]); // Write the subkey. - key.CopyTo(payload.Slice(13 + salt.Length)); + key.CopyTo(payload[(13 + salt.Length)..]); return payload; } diff --git a/src/OpenIddict.EntityFramework.Models/OpenIddict.EntityFramework.Models.csproj b/src/OpenIddict.EntityFramework.Models/OpenIddict.EntityFramework.Models.csproj index ab3fb342..587e7da4 100644 --- a/src/OpenIddict.EntityFramework.Models/OpenIddict.EntityFramework.Models.csproj +++ b/src/OpenIddict.EntityFramework.Models/OpenIddict.EntityFramework.Models.csproj @@ -2,6 +2,7 @@ net461;netstandard2.0 + true diff --git a/src/OpenIddict.EntityFrameworkCore.Models/OpenIddict.EntityFrameworkCore.Models.csproj b/src/OpenIddict.EntityFrameworkCore.Models/OpenIddict.EntityFrameworkCore.Models.csproj index 6a59bf7a..f7bf28c4 100644 --- a/src/OpenIddict.EntityFrameworkCore.Models/OpenIddict.EntityFrameworkCore.Models.csproj +++ b/src/OpenIddict.EntityFrameworkCore.Models/OpenIddict.EntityFrameworkCore.Models.csproj @@ -2,6 +2,7 @@ net461;netstandard2.0 + true diff --git a/src/OpenIddict.MongoDb.Models/OpenIddict.MongoDb.Models.csproj b/src/OpenIddict.MongoDb.Models/OpenIddict.MongoDb.Models.csproj index 439170e5..eb28110b 100644 --- a/src/OpenIddict.MongoDb.Models/OpenIddict.MongoDb.Models.csproj +++ b/src/OpenIddict.MongoDb.Models/OpenIddict.MongoDb.Models.csproj @@ -2,6 +2,7 @@ net461;netstandard2.0 + true false false diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs index e30763eb..0e7d00c7 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs @@ -760,7 +760,7 @@ public static partial class OpenIddictServerAspNetCoreHandlers try { - var value = header.Substring("Basic ".Length).Trim(); + var value = header["Basic ".Length..].Trim(); var data = Encoding.ASCII.GetString(Convert.FromBase64String(value)); var index = data.IndexOf(':'); @@ -775,8 +775,8 @@ public static partial class OpenIddictServerAspNetCoreHandlers } // Attach the basic authentication credentials to the request message. - context.Transaction.Request.ClientId = UnescapeDataString(data.Substring(0, index)); - context.Transaction.Request.ClientSecret = UnescapeDataString(data.Substring(index + 1)); + context.Transaction.Request.ClientId = UnescapeDataString(data[..index]); + context.Transaction.Request.ClientSecret = UnescapeDataString(data[(index + 1)..]); return default; } @@ -843,7 +843,7 @@ public static partial class OpenIddictServerAspNetCoreHandlers } // Attach the access token to the request message. - context.Transaction.Request.AccessToken = header.Substring("Bearer ".Length); + context.Transaction.Request.AccessToken = header["Bearer ".Length..]; return default; } diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs index 56b046e0..2ea020ab 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs @@ -318,22 +318,22 @@ public static partial class OpenIddictServerOwinHandlers { // If the property ends with #string, represent it as a string parameter. string key when key.EndsWith(PropertyTypes.String, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.String.Length), + Name: key[..^PropertyTypes.String.Length], Value: new OpenIddictParameter(property.Value)), // If the property ends with #boolean, return it as a boolean parameter. string key when key.EndsWith(PropertyTypes.Boolean, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Boolean.Length), + Name: key[..^PropertyTypes.Boolean.Length], Value: new OpenIddictParameter(bool.Parse(property.Value))), // If the property ends with #integer, return it as an integer parameter. string key when key.EndsWith(PropertyTypes.Integer, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Integer.Length), + Name: key[..^PropertyTypes.Integer.Length], Value: new OpenIddictParameter(long.Parse(property.Value, CultureInfo.InvariantCulture))), // If the property ends with #json, return it as a JSON parameter. string key when key.EndsWith(PropertyTypes.Json, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Json.Length), + Name: key[..^PropertyTypes.Json.Length], Value: new OpenIddictParameter(JsonSerializer.Deserialize(property.Value))), _ => default @@ -438,22 +438,22 @@ public static partial class OpenIddictServerOwinHandlers { // If the property ends with #string, represent it as a string parameter. string key when key.EndsWith(PropertyTypes.String, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.String.Length), + Name: key[..^PropertyTypes.String.Length], Value: new OpenIddictParameter(property.Value)), // If the property ends with #boolean, return it as a boolean parameter. string key when key.EndsWith(PropertyTypes.Boolean, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Boolean.Length), + Name: key[..^PropertyTypes.Boolean.Length], Value: new OpenIddictParameter(bool.Parse(property.Value))), // If the property ends with #integer, return it as an integer parameter. string key when key.EndsWith(PropertyTypes.Integer, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Integer.Length), + Name: key[..^PropertyTypes.Integer.Length], Value: new OpenIddictParameter(long.Parse(property.Value, CultureInfo.InvariantCulture))), // If the property ends with #json, return it as a JSON parameter. string key when key.EndsWith(PropertyTypes.Json, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Json.Length), + Name: key[..^PropertyTypes.Json.Length], Value: new OpenIddictParameter(JsonSerializer.Deserialize(property.Value))), _ => default @@ -517,22 +517,22 @@ public static partial class OpenIddictServerOwinHandlers { // If the property ends with #string, represent it as a string parameter. string key when key.EndsWith(PropertyTypes.String, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.String.Length), + Name: key[..^PropertyTypes.String.Length], Value: new OpenIddictParameter(property.Value)), // If the property ends with #boolean, return it as a boolean parameter. string key when key.EndsWith(PropertyTypes.Boolean, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Boolean.Length), + Name: key[..^PropertyTypes.Boolean.Length], Value: new OpenIddictParameter(bool.Parse(property.Value))), // If the property ends with #integer, return it as an integer parameter. string key when key.EndsWith(PropertyTypes.Integer, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Integer.Length), + Name: key[..^PropertyTypes.Integer.Length], Value: new OpenIddictParameter(long.Parse(property.Value, CultureInfo.InvariantCulture))), // If the property ends with #json, return it as a JSON parameter. string key when key.EndsWith(PropertyTypes.Json, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Json.Length), + Name: key[..^PropertyTypes.Json.Length], Value: new OpenIddictParameter(JsonSerializer.Deserialize(property.Value))), _ => default @@ -815,7 +815,7 @@ public static partial class OpenIddictServerOwinHandlers try { - var value = header.Substring("Basic ".Length).Trim(); + var value = header["Basic ".Length..].Trim(); var data = Encoding.ASCII.GetString(Convert.FromBase64String(value)); var index = data.IndexOf(':'); @@ -830,8 +830,8 @@ public static partial class OpenIddictServerOwinHandlers } // Attach the basic authentication credentials to the request message. - context.Transaction.Request.ClientId = UnescapeDataString(data.Substring(0, index)); - context.Transaction.Request.ClientSecret = UnescapeDataString(data.Substring(index + 1)); + context.Transaction.Request.ClientId = UnescapeDataString(data[..index]); + context.Transaction.Request.ClientSecret = UnescapeDataString(data[(index + 1)..]); return default; } @@ -898,7 +898,7 @@ public static partial class OpenIddictServerOwinHandlers } // Attach the access token to the request message. - context.Transaction.Request.AccessToken = header.Substring("Bearer ".Length); + context.Transaction.Request.AccessToken = header["Bearer ".Length..]; return default; } diff --git a/src/OpenIddict.Server/OpenIddictServerConfiguration.cs b/src/OpenIddict.Server/OpenIddictServerConfiguration.cs index a5a4770d..5768572b 100644 --- a/src/OpenIddict.Server/OpenIddictServerConfiguration.cs +++ b/src/OpenIddict.Server/OpenIddictServerConfiguration.cs @@ -318,7 +318,7 @@ public class OpenIddictServerConfiguration : IPostConfigureOptions(values, StringComparer.Ordinal).SetEquals(types)) { return true; diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Discovery.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Discovery.cs index 7c90f303..fd0d583a 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Discovery.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Discovery.cs @@ -393,7 +393,7 @@ public static partial class OpenIddictServerHandlers // for Uri's constructor to correctly compute correct absolute URLs. if (endpoint.OriginalString.StartsWith("/", StringComparison.Ordinal)) { - endpoint = new Uri(endpoint.OriginalString.Substring(1, endpoint.OriginalString.Length - 1), UriKind.Relative); + endpoint = new Uri(endpoint.OriginalString[1..], UriKind.Relative); } return new Uri(issuer, endpoint); diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.cs index dd58baa7..6654e7e0 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.cs @@ -3056,7 +3056,7 @@ public static partial class OpenIddictServerHandlers // for Uri's constructor to correctly compute correct absolute URLs. if (endpoint.OriginalString.StartsWith("/", StringComparison.Ordinal)) { - endpoint = new Uri(endpoint.OriginalString.Substring(1, endpoint.OriginalString.Length - 1), UriKind.Relative); + endpoint = new Uri(endpoint.OriginalString[1..], UriKind.Relative); } return new Uri(issuer, endpoint); diff --git a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandlers.cs b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandlers.cs index 43eec9e5..e6888563 100644 --- a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandlers.cs +++ b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandlers.cs @@ -163,7 +163,7 @@ public static partial class OpenIddictValidationAspNetCoreHandlers string? header = request.Headers[HeaderNames.Authorization]; if (!string.IsNullOrEmpty(header) && header.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase)) { - context.AccessToken = header.Substring("Bearer ".Length); + context.AccessToken = header["Bearer ".Length..]; return default; } diff --git a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandlers.cs b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandlers.cs index aa44e9e3..0e1724af 100644 --- a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandlers.cs +++ b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandlers.cs @@ -163,7 +163,7 @@ public static partial class OpenIddictValidationOwinHandlers string header = request.Headers[Headers.Authorization]; if (!string.IsNullOrEmpty(header) && header.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase)) { - context.AccessToken = header.Substring("Bearer ".Length); + context.AccessToken = header["Bearer ".Length..]; return default; } @@ -322,22 +322,22 @@ public static partial class OpenIddictValidationOwinHandlers { // If the property ends with #string, represent it as a string parameter. string key when key.EndsWith(PropertyTypes.String, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.String.Length), + Name: key[..^PropertyTypes.String.Length], Value: new OpenIddictParameter(property.Value)), // If the property ends with #boolean, return it as a boolean parameter. string key when key.EndsWith(PropertyTypes.Boolean, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Boolean.Length), + Name: key[..^PropertyTypes.Boolean.Length], Value: new OpenIddictParameter(bool.Parse(property.Value))), // If the property ends with #integer, return it as an integer parameter. string key when key.EndsWith(PropertyTypes.Integer, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Integer.Length), + Name: key[..^PropertyTypes.Integer.Length], Value: new OpenIddictParameter(long.Parse(property.Value, CultureInfo.InvariantCulture))), // If the property ends with #json, return it as a JSON parameter. string key when key.EndsWith(PropertyTypes.Json, StringComparison.OrdinalIgnoreCase) => ( - Name: key.Substring(0, key.Length - PropertyTypes.Json.Length), + Name: key[..^PropertyTypes.Json.Length], Value: new OpenIddictParameter(JsonSerializer.Deserialize(property.Value))), _ => default diff --git a/src/OpenIddict.Validation/OpenIddictValidationConfiguration.cs b/src/OpenIddict.Validation/OpenIddictValidationConfiguration.cs index 00f81e34..b23dabea 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationConfiguration.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationConfiguration.cs @@ -126,8 +126,7 @@ public class OpenIddictValidationConfiguration : IPostConfigureOptions new[] { issuer.AbsoluteUri, // Uri.AbsoluteUri is normalized and always contains a trailing slash. - issuer.AbsoluteUri.Substring(0, issuer.AbsoluteUri.Length - 1) + issuer.AbsoluteUri[..^1] }, Uri issuer => new[] { issuer.AbsoluteUri } diff --git a/test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTestClient.cs b/test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTestClient.cs index d0c2ed3e..9ce0c4d9 100644 --- a/test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTestClient.cs +++ b/test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTestClient.cs @@ -435,13 +435,13 @@ public class OpenIddictServerIntegrationTestClient : IAsyncDisposable continue; } - var name = line.Substring(0, index); + var name = line[..index]; if (string.IsNullOrEmpty(name)) { continue; } - var value = line.Substring(index + 1); + var value = line[(index + 1)..]; parameters.Add(new KeyValuePair(name, value)); } diff --git a/test/OpenIddict.Validation.IntegrationTests/OpenIddictValidationIntegrationTestClient.cs b/test/OpenIddict.Validation.IntegrationTests/OpenIddictValidationIntegrationTestClient.cs index d1c2ae19..819e1454 100644 --- a/test/OpenIddict.Validation.IntegrationTests/OpenIddictValidationIntegrationTestClient.cs +++ b/test/OpenIddict.Validation.IntegrationTests/OpenIddictValidationIntegrationTestClient.cs @@ -435,13 +435,13 @@ public class OpenIddictValidationIntegrationTestClient : IAsyncDisposable continue; } - var name = line.Substring(0, index); + var name = line[..index]; if (string.IsNullOrEmpty(name)) { continue; } - var value = line.Substring(index + 1); + var value = line[(index + 1)..]; parameters.Add(new KeyValuePair(name, value)); }