Skip to content

Commit

Permalink
precondition ** to be the last component (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevapple authored Apr 16, 2020
1 parent 35da702 commit ee590c4
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Sources/RoutingKit/TrieRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ public final class TrieRouter<Output>: Router, CustomStringConvertible {
var current = self.root

// for each dynamic path in the route get the appropriate
// child generating a new one if necessary
for component in path {
current = current.buildOrFetchChild(for: component, options: self.options)
// child, generate a new one if necessary
for (index, component) in path.enumerated() {
switch component {
case .catchall:
precondition(index == path.count - 1, "Catchall ('\(component)') must be the last component in a path.")
fallthrough
default:
current = current.buildOrFetchChild(for: component, options: self.options)
}
}

// if this node already has output, we are overriding a route
Expand Down Expand Up @@ -208,9 +214,8 @@ extension TrieRouter {
desc.append("\(name)")
desc.append(parameter.description.indented())
}
if let catchall = self.catchall {
if let _ = self.catchall {
desc.append("→ *")
desc.append(catchall.description.indented())
}
if let anything = self.anything {
desc.append("→ :")
Expand Down

0 comments on commit ee590c4

Please sign in to comment.