Skip to content

Commit 9306861

Browse files
committed
Better candidate checking.
1 parent 57bbbfa commit 9306861

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/Umbraco.Web.Website/Routing/NotFoundSelectorPolicy.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal class NotFoundSelectorPolicy : MatcherPolicy, IEndpointSelectorPolicy
2424
public NotFoundSelectorPolicy(EndpointDataSource endpointDataSource)
2525
{
2626
_notFound = new Lazy<Endpoint>(GetNotFoundEndpoint);
27-
_endpointDataSource = endpointDataSource;
27+
_endpointDataSource = endpointDataSource;
2828
}
2929

3030
// return the endpoint for the RenderController.Index action.
@@ -46,7 +46,7 @@ public bool AppliesToEndpoints(IReadOnlyList<Endpoint> endpoints)
4646
{
4747
// Don't apply this filter to any endpoint group that is a controller route
4848
// i.e. only dynamic routes.
49-
foreach(Endpoint endpoint in endpoints)
49+
foreach (Endpoint endpoint in endpoints)
5050
{
5151
ControllerAttribute controller = endpoint.Metadata?.GetMetadata<ControllerAttribute>();
5252
if (controller != null)
@@ -61,7 +61,7 @@ public bool AppliesToEndpoints(IReadOnlyList<Endpoint> endpoints)
6161

6262
public Task ApplyAsync(HttpContext httpContext, CandidateSet candidates)
6363
{
64-
if (candidates.Count == 1 && candidates[0].Values == null)
64+
if (AllInvalid(candidates))
6565
{
6666
UmbracoRouteValues umbracoRouteValues = httpContext.Features.Get<UmbracoRouteValues>();
6767
if (umbracoRouteValues?.PublishedRequest != null
@@ -72,8 +72,20 @@ public Task ApplyAsync(HttpContext httpContext, CandidateSet candidates)
7272
httpContext.SetEndpoint(_notFound.Value);
7373
}
7474
}
75-
76-
return Task.CompletedTask;
75+
76+
return Task.CompletedTask;
77+
}
78+
79+
private static bool AllInvalid(CandidateSet candidates)
80+
{
81+
for (int i = 0; i < candidates.Count; i++)
82+
{
83+
if (candidates.IsValidCandidate(i))
84+
{
85+
return false;
86+
}
87+
}
88+
return true;
7789
}
7890
}
7991
}

0 commit comments

Comments
 (0)