소스 검색

Fixed issue #98 ( "Trailing slash on last parameter value").

Damian Kołakowski 10 년 전
부모
커밋
1ce84ca3ff
1개의 변경된 파일8개의 추가작업 그리고 2개의 파일을 삭제
  1. 8 2
      Sources/HttpRouter.swift

+ 8 - 2
Sources/HttpRouter.swift

@@ -83,8 +83,14 @@ public class HttpRouter {
         let variableNodes = node.nodes.filter { $0.0.characters.first == ":" }
         if let variableNode = variableNodes.first {
             if variableNode.1.nodes.count == 0 {
-                // if it's the last element of the pattern and it's a variable, stop the routing.
-                params[variableNode.0] = pathToken + "/" + generator.joinWithSeparator("/")
+                // if it's the last element of the pattern and it's a variable, stop the search and
+                // append a tail as a value for the variable.
+                let tail = generator.joinWithSeparator("/")
+                if tail.utf8.count > 0 {
+                    params[variableNode.0] = pathToken + "/" + tail
+                } else {
+                    params[variableNode.0] = pathToken
+                }
                 return variableNode.1.handler
             }
             params[variableNode.0] = pathToken