diff --git a/src/Microsoft.AspNetCore.Routing/Internal/DfaGraphWriter.cs b/src/Microsoft.AspNetCore.Routing/Internal/DfaGraphWriter.cs index 5a42cf493b..ed1c3f2d9f 100644 --- a/src/Microsoft.AspNetCore.Routing/Internal/DfaGraphWriter.cs +++ b/src/Microsoft.AspNetCore.Routing/Internal/DfaGraphWriter.cs @@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Routing.Internal // Assign each node a sequential index. var visited = new Dictionary(); - var tree = builder.BuildDfaTree(); + var tree = builder.BuildDfaTree(includeLabel: true); writer.WriteLine("digraph DFA {"); tree.Visit(WriteNode); diff --git a/src/Microsoft.AspNetCore.Routing/Matching/DfaMatcherBuilder.cs b/src/Microsoft.AspNetCore.Routing/Matching/DfaMatcherBuilder.cs index 3592918a9a..7cc748ddf4 100644 --- a/src/Microsoft.AspNetCore.Routing/Matching/DfaMatcherBuilder.cs +++ b/src/Microsoft.AspNetCore.Routing/Matching/DfaMatcherBuilder.cs @@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Routing.Matching _endpoints.Add(endpoint); } - public DfaNode BuildDfaTree() + public DfaNode BuildDfaTree(bool includeLabel = false) { // We build the tree by doing a BFS over the list of entries. This is important // because a 'parameter' node can also traverse the same paths that literal nodes @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Routing.Matching var work = new List<(RouteEndpoint endpoint, List parents)>(_endpoints.Count); List<(RouteEndpoint endpoint, List parents)> previousWork = null; - var root = new DfaNode() { PathDepth = 0, Label = "/" }; + var root = new DfaNode() { PathDepth = 0, Label = includeLabel ? "/" : null }; // To prepare for this we need to compute the max depth, as well as // a seed list of items to process (entry, root). @@ -149,7 +149,7 @@ namespace Microsoft.AspNetCore.Routing.Matching next = new DfaNode() { PathDepth = parent.PathDepth + 1, - Label = parent.Label + literal + "/", + Label = includeLabel ? parent.Label + literal + "/" : null, }; parent.AddLiteral(literal, next); } @@ -180,7 +180,7 @@ namespace Microsoft.AspNetCore.Routing.Matching parent.CatchAll = new DfaNode() { PathDepth = parent.PathDepth + 1, - Label = parent.Label + "{*...}/", + Label = includeLabel ? parent.Label + "{*...}/" : null, }; // The catchall node just loops. @@ -197,7 +197,7 @@ namespace Microsoft.AspNetCore.Routing.Matching parent.Parameters = new DfaNode() { PathDepth = parent.PathDepth + 1, - Label = parent.Label + "{...}/", + Label = includeLabel ? parent.Label + "{...}/" : null, }; } @@ -219,7 +219,7 @@ namespace Microsoft.AspNetCore.Routing.Matching parent.Parameters = new DfaNode() { PathDepth = parent.PathDepth + 1, - Label = parent.Label + "{...}/", + Label = includeLabel ? parent.Label + "{...}/" : null, }; } @@ -273,7 +273,13 @@ namespace Microsoft.AspNetCore.Routing.Matching public override Matcher Build() { - var root = BuildDfaTree(); +#if DEBUG + var includeLabel = true; +#else + var includeLabel = false; +#endif + + var root = BuildDfaTree(includeLabel); // State count is the number of nodes plus an exit state var stateCount = 1; @@ -613,7 +619,8 @@ namespace Microsoft.AspNetCore.Routing.Matching var next = new DfaNode() { - Label = parent.Label + " " + edge.State.ToString(), + // If parent label is null then labels are not being included + Label = (parent.Label != null) ? parent.Label + " " + edge.State.ToString() : null, }; if (edge.Endpoints.Count > 0) diff --git a/src/Microsoft.AspNetCore.Routing/Matching/HttpMethodMatcherPolicy.cs b/src/Microsoft.AspNetCore.Routing/Matching/HttpMethodMatcherPolicy.cs index 652a290230..f6149531d4 100644 --- a/src/Microsoft.AspNetCore.Routing/Matching/HttpMethodMatcherPolicy.cs +++ b/src/Microsoft.AspNetCore.Routing/Matching/HttpMethodMatcherPolicy.cs @@ -195,9 +195,14 @@ namespace Microsoft.AspNetCore.Routing.Matching edges[new EdgeKey(AnyMethod, false)] = matches; } - return edges - .Select(kvp => new PolicyNodeEdge(kvp.Key, kvp.Value)) - .ToArray(); + var policyNodeEdges = new PolicyNodeEdge[edges.Count]; + var index = 0; + foreach (var kvp in edges) + { + policyNodeEdges[index++] = new PolicyNodeEdge(kvp.Key, kvp.Value); + } + + return policyNodeEdges; (IReadOnlyList httpMethods, bool acceptCorsPreflight) GetHttpMethods(Endpoint e) {