Add flag for including label with DfaNodes (#769)
This commit is contained in:
parent
fe8c633224
commit
dbebdbecd6
|
|
@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
||||||
// Assign each node a sequential index.
|
// Assign each node a sequential index.
|
||||||
var visited = new Dictionary<DfaNode, int>();
|
var visited = new Dictionary<DfaNode, int>();
|
||||||
|
|
||||||
var tree = builder.BuildDfaTree();
|
var tree = builder.BuildDfaTree(includeLabel: true);
|
||||||
|
|
||||||
writer.WriteLine("digraph DFA {");
|
writer.WriteLine("digraph DFA {");
|
||||||
tree.Visit(WriteNode);
|
tree.Visit(WriteNode);
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Routing.Matching
|
||||||
_endpoints.Add(endpoint);
|
_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
|
// 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
|
// 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<DfaNode> parents)>(_endpoints.Count);
|
var work = new List<(RouteEndpoint endpoint, List<DfaNode> parents)>(_endpoints.Count);
|
||||||
List<(RouteEndpoint endpoint, List<DfaNode> parents)> previousWork = null;
|
List<(RouteEndpoint endpoint, List<DfaNode> 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
|
// To prepare for this we need to compute the max depth, as well as
|
||||||
// a seed list of items to process (entry, root).
|
// a seed list of items to process (entry, root).
|
||||||
|
|
@ -149,7 +149,7 @@ namespace Microsoft.AspNetCore.Routing.Matching
|
||||||
next = new DfaNode()
|
next = new DfaNode()
|
||||||
{
|
{
|
||||||
PathDepth = parent.PathDepth + 1,
|
PathDepth = parent.PathDepth + 1,
|
||||||
Label = parent.Label + literal + "/",
|
Label = includeLabel ? parent.Label + literal + "/" : null,
|
||||||
};
|
};
|
||||||
parent.AddLiteral(literal, next);
|
parent.AddLiteral(literal, next);
|
||||||
}
|
}
|
||||||
|
|
@ -180,7 +180,7 @@ namespace Microsoft.AspNetCore.Routing.Matching
|
||||||
parent.CatchAll = new DfaNode()
|
parent.CatchAll = new DfaNode()
|
||||||
{
|
{
|
||||||
PathDepth = parent.PathDepth + 1,
|
PathDepth = parent.PathDepth + 1,
|
||||||
Label = parent.Label + "{*...}/",
|
Label = includeLabel ? parent.Label + "{*...}/" : null,
|
||||||
};
|
};
|
||||||
|
|
||||||
// The catchall node just loops.
|
// The catchall node just loops.
|
||||||
|
|
@ -197,7 +197,7 @@ namespace Microsoft.AspNetCore.Routing.Matching
|
||||||
parent.Parameters = new DfaNode()
|
parent.Parameters = new DfaNode()
|
||||||
{
|
{
|
||||||
PathDepth = parent.PathDepth + 1,
|
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()
|
parent.Parameters = new DfaNode()
|
||||||
{
|
{
|
||||||
PathDepth = parent.PathDepth + 1,
|
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()
|
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
|
// State count is the number of nodes plus an exit state
|
||||||
var stateCount = 1;
|
var stateCount = 1;
|
||||||
|
|
@ -613,7 +619,8 @@ namespace Microsoft.AspNetCore.Routing.Matching
|
||||||
|
|
||||||
var next = new DfaNode()
|
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)
|
if (edge.Endpoints.Count > 0)
|
||||||
|
|
|
||||||
|
|
@ -195,9 +195,14 @@ namespace Microsoft.AspNetCore.Routing.Matching
|
||||||
edges[new EdgeKey(AnyMethod, false)] = matches;
|
edges[new EdgeKey(AnyMethod, false)] = matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
return edges
|
var policyNodeEdges = new PolicyNodeEdge[edges.Count];
|
||||||
.Select(kvp => new PolicyNodeEdge(kvp.Key, kvp.Value))
|
var index = 0;
|
||||||
.ToArray();
|
foreach (var kvp in edges)
|
||||||
|
{
|
||||||
|
policyNodeEdges[index++] = new PolicyNodeEdge(kvp.Key, kvp.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return policyNodeEdges;
|
||||||
|
|
||||||
(IReadOnlyList<string> httpMethods, bool acceptCorsPreflight) GetHttpMethods(Endpoint e)
|
(IReadOnlyList<string> httpMethods, bool acceptCorsPreflight) GetHttpMethods(Endpoint e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue