Skip to content

Commit

Permalink
enable nullable in StringsExtensions
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Dec 20, 2024
1 parent 8458ae0 commit d3e266f
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions identity-server/src/IdentityServer/Extensions/StringsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See LICENSE in the project root for license information.


#nullable enable
using Microsoft.AspNetCore.WebUtilities;
using System;
using System.Collections.Generic;
Expand All @@ -16,7 +17,7 @@ namespace Duende.IdentityServer.Extensions;
internal static class StringExtensions
{
[DebuggerStepThrough]
public static string ToSpaceSeparatedString(this IEnumerable<string> list)
public static string ToSpaceSeparatedString(this IEnumerable<string>? list)
{
if (list == null)
{
Expand All @@ -33,7 +34,7 @@ public static IEnumerable<string> FromSpaceSeparatedString(this string input)
return input.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList();
}

public static List<string> ParseScopesString(this string scopes)
public static List<string>? ParseScopesString(this string scopes)
{
if (scopes.IsMissing())
{
Expand All @@ -53,13 +54,13 @@ public static List<string> ParseScopesString(this string scopes)
}

[DebuggerStepThrough]
public static bool IsMissing([NotNullWhen(false)]this string value)
public static bool IsMissing([NotNullWhen(false)] this string? value)
{
return string.IsNullOrWhiteSpace(value);
}

[DebuggerStepThrough]
public static bool IsMissingOrTooLong(this string value, int maxLength)
public static bool IsMissingOrTooLong(this string? value, int maxLength)
{
if (string.IsNullOrWhiteSpace(value))
{
Expand All @@ -74,13 +75,14 @@ public static bool IsMissingOrTooLong(this string value, int maxLength)
}

[DebuggerStepThrough]
public static bool IsPresent([NotNullWhen(true)] this string value)
public static bool IsPresent([NotNullWhen(true)] this string? value)
{
return !string.IsNullOrWhiteSpace(value);
}

[DebuggerStepThrough]
public static string EnsureLeadingSlash(this string url)
[return: NotNullIfNotNull("url")]
public static string? EnsureLeadingSlash(this string? url)
{
if (url != null && !url.StartsWith('/'))
{
Expand All @@ -91,7 +93,8 @@ public static string EnsureLeadingSlash(this string url)
}

[DebuggerStepThrough]
public static string EnsureTrailingSlash(this string url)
[return: NotNullIfNotNull("url")]
public static string? EnsureTrailingSlash(this string? url)
{
if (url != null && !url.EndsWith('/'))
{
Expand All @@ -102,7 +105,8 @@ public static string EnsureTrailingSlash(this string url)
}

[DebuggerStepThrough]
public static string RemoveLeadingSlash(this string url)
[return: NotNullIfNotNull("url")]
public static string? RemoveLeadingSlash(this string? url)
{
if (url != null && url.StartsWith('/'))
{
Expand All @@ -113,7 +117,8 @@ public static string RemoveLeadingSlash(this string url)
}

[DebuggerStepThrough]
public static string RemoveTrailingSlash(this string url)
[return: NotNullIfNotNull("url")]
public static string? RemoveTrailingSlash(this string? url)
{
if (url != null && url.EndsWith('/'))
{
Expand All @@ -124,7 +129,7 @@ public static string RemoveTrailingSlash(this string url)
}

[DebuggerStepThrough]
public static string CleanUrlPath(this string url)
public static string CleanUrlPath(this string? url)
{
if (String.IsNullOrWhiteSpace(url)) url = "/";

Expand All @@ -137,7 +142,7 @@ public static string CleanUrlPath(this string url)
}

[DebuggerStepThrough]
public static bool IsLocalUrl(this string url)
public static bool IsLocalUrl([NotNullWhen(false)] this string? url)
{
// This implementation is a copy of a https://github.com/dotnet/aspnetcore/blob/3f1acb59718cadf111a0a796681e3d3509bb3381/src/Mvc/Mvc.Core/src/Routing/UrlHelperBase.cs#L315
// We originally copied that code to avoid a dependency, but we could potentially remove this entirely by switching to the Microsoft.NET.Sdk.Web sdk.
Expand Down Expand Up @@ -248,7 +253,7 @@ public static string AddHashFragment(this string url, string query)
}

[DebuggerStepThrough]
public static NameValueCollection ReadQueryStringAsNameValueCollection(this string url)
public static NameValueCollection ReadQueryStringAsNameValueCollection(this string? url)
{
if (url != null)
{
Expand All @@ -267,7 +272,7 @@ public static NameValueCollection ReadQueryStringAsNameValueCollection(this stri
return new NameValueCollection();
}

public static string GetOrigin(this string url)
public static string? GetOrigin(this string? url)
{
if (url != null)
{
Expand Down

0 comments on commit d3e266f

Please sign in to comment.