Skip to content

Commit

Permalink
Merge pull request #130 from mvitz/fix-context-list-with-regex
Browse files Browse the repository at this point in the history
Fix context use with list and regex.
  • Loading branch information
weavejester committed Dec 2, 2014
2 parents 2ae60a4 + 13bea7b commit a963e00
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compojure/core.clj
Expand Up @@ -195,7 +195,7 @@
`(clout/route-compile ~(str route ":__path-info") ~re-context)
(vector? route)
`(clout/route-compile
~(str (first route) ":__path-info")
(str ~(first route) ":__path-info")
~(merge (apply hash-map (rest route)) re-context))
:else
`(clout/route-compile (str ~route ":__path-info") ~re-context))))
Expand Down
6 changes: 6 additions & 0 deletions test/compojure/core_test.clj
Expand Up @@ -139,6 +139,12 @@
(is (map? (handler (mock/request :get "/foo/10"))))
(is (nil? (handler (mock/request :get "/bar/10"))))))

(testing "list with regex matching"
(let [handler (context [(str "/foo" "/:id") :id #"\d+"] [id] identity)]
(is (map? (handler (mock/request :get "/foo/10"))))
(is (nil? (handler (mock/request :get "/foo/ab"))))
(is (nil? (handler (mock/request :get "/bar/10"))))))

(testing "context key"
(let [handler (context "/foo/:id" [id] :context)]
(are [url ctx] (= (handler (mock/request :get url)) ctx)
Expand Down

0 comments on commit a963e00

Please sign in to comment.