Skip to content

Commit

Permalink
Prevent infinite recursion. Fixes #1017
Browse files Browse the repository at this point in the history
  • Loading branch information
commonsensesoftware committed Aug 14, 2023
1 parent f29831e commit 592559c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ public IReadOnlyList<string> RawRequestedApiVersions
{
if ( rawApiVersions is null )
{
var reader = context.RequestServices.GetService<IApiVersionReader>()
?? ApiVersionReader.Combine(
new QueryStringApiVersionReader(),
new UrlSegmentApiVersionReader() );

var reader = context.RequestServices.GetService<IApiVersionReader>() ?? ApiVersionReader.Default;
rawApiVersions = reader.Read( context.Request );
}

Expand Down
8 changes: 8 additions & 0 deletions src/Common/src/Common/ApiVersionReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ namespace Asp.Versioning;
#endif
public static class ApiVersionReader
{
private static IApiVersionReader? @default;

/// <summary>
/// Gets the default API version reader.
/// </summary>
/// <value>The default <see cref="IApiVersionReader"/>.</value>
public static IApiVersionReader Default => @default ??= Combine( new QueryStringApiVersionReader(), new UrlSegmentApiVersionReader() );

/// <summary>
/// Returns a new API version reader that is a combination of the specified set.
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions src/Common/src/Common/ApiVersioningOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace Asp.Versioning;
#if NETFRAMEWORK
using System.Net;
#endif
using static Asp.Versioning.ApiVersionReader;

/// <summary>
/// Represents the possible options for API versioning.
Expand Down Expand Up @@ -73,7 +72,7 @@ public partial class ApiVersioningOptions
#endif
public IApiVersionReader ApiVersionReader
{
get => apiVersionReader ??= Combine( new QueryStringApiVersionReader(), new UrlSegmentApiVersionReader() );
get => apiVersionReader ??= Versioning.ApiVersionReader.Default;
set => apiVersionReader = value;
}

Expand Down

0 comments on commit 592559c

Please sign in to comment.