Skip to content
Open
Show file tree
Hide file tree
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
29 changes: 16 additions & 13 deletions src/Open.IdentityServer/src/Extensions/StringsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Text.Encodings.Web;

#nullable enable

namespace Open.IdentityServer.Extensions;

internal static class StringExtensions
Expand Down Expand Up @@ -47,7 +50,7 @@ public static IEnumerable<string> FromSpaceSeparatedString(this string input)
return input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
}

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

[DebuggerStepThrough]
public static bool IsMissing(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 @@ -89,13 +92,13 @@ public static bool IsMissingOrTooLong(this string value, int maxLength)
}

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

[DebuggerStepThrough]
public static string EnsureLeadingSlash(this string url)
public static string? EnsureLeadingSlash(this string? url)
{
if (url != null && !url.StartsWith("/"))
{
Expand All @@ -106,7 +109,7 @@ public static string EnsureLeadingSlash(this string url)
}

[DebuggerStepThrough]
public static string EnsureTrailingSlash(this string url)
public static string? EnsureTrailingSlash(this string? url)
{
if (url != null && !url.EndsWith("/"))
{
Expand All @@ -117,7 +120,7 @@ public static string EnsureTrailingSlash(this string url)
}

[DebuggerStepThrough]
public static string RemoveLeadingSlash(this string url)
public static string? RemoveLeadingSlash(this string? url)
{
if (url != null && url.StartsWith("/"))
{
Expand All @@ -128,7 +131,7 @@ public static string RemoveLeadingSlash(this string url)
}

[DebuggerStepThrough]
public static string RemoveTrailingSlash(this string url)
public static string? RemoveTrailingSlash(this string? url)
{
if (url != null && url.EndsWith("/"))
{
Expand All @@ -139,9 +142,9 @@ 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 = "/";
if (string.IsNullOrWhiteSpace(url)) url = "/";

if (url != "/" && url.EndsWith("/"))
{
Expand All @@ -153,7 +156,7 @@ public static string CleanUrlPath(this string url)

[DebuggerStepThrough]
// Clone of UrlHelperBase.CheckIsLocalUrl from https://github.com/dotnet/aspnetcore/blob/3f1acb59718cadf111a0a796681e3d3509bb3381/src/Mvc/Mvc.Core/src/Routing/UrlHelperBase.cs
public static bool IsLocalUrl(this string url)
public static bool IsLocalUrl(this string? url)
{
if (string.IsNullOrEmpty(url))
{
Expand Down Expand Up @@ -246,7 +249,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 @@ -266,7 +269,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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Modified by Rock Solid Knowledge Ltd. Copyright in modifications 2026, Rock Solid Knowledge Ltd.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
#nullable enable

Expand All @@ -11,13 +12,13 @@ namespace IdentityServer.IntegrationTests.Utility;
internal static class InternalStringExtensions
{
[DebuggerStepThrough]
public static bool IsMissing(this string value)
public static bool IsMissing([NotNullWhen(false)] this string? value)
{
return string.IsNullOrWhiteSpace(value);
}

[DebuggerStepThrough]
public static bool IsPresent(this string value)
public static bool IsPresent([NotNullWhen(true)] this string? value)
{
return !(value.IsMissing());
}
Expand Down
8 changes: 6 additions & 2 deletions src/Storage/src/Extensions/StringsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Modified by Rock Solid Knowledge Ltd. Copyright in modifications 2026, Rock Solid Knowledge Ltd.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.


using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

#nullable enable

namespace Open.IdentityServer.Extensions;

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

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