Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable nullable in StringsExtensions #1679

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(true)] 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