Permalink
Browse files

Merge pull request #7 from ptaoussanis/master

Added support for scheme-relative URLs.
  • Loading branch information...
2 parents e22a500 + 403e555 commit ac9360282efd62204c9e76846d2a82a0faae0d28 @weavejester committed Jun 22, 2012
Showing with 23 additions and 3 deletions.
  1. +9 −0 README.md
  2. +3 −2 src/clout/core.clj
  3. +11 −1 test/clout/test/core.clj
View
@@ -33,6 +33,15 @@ Clout can also match absolute routes:
(request :get "http://subdomain.example.com/"))
{}
+And scheme-relative routes:
+
+ user=> (route-matches "//subdomain.example.com/"
+ (request :get "http://subdomain.example.com/"))
+ {}
+ user=> (route-matches "//subdomain.example.com/"
+ (request :get "https://subdomain.example.com/"))
+ {}
+
Clout supports both keywords and wildcards. Keywords (like ":title") will
match any character but the following: `/ . , ; ?`. Wildcards (*) will match
anything.
View
@@ -112,9 +112,9 @@
(recur results src clauses))))))
(defn- absolute-url?
- "True if the path contains an absolute URL."
+ "True if the path contains an absolute or scheme-relative URL."
[path]
- (boolean (re-matches #"https?://.*" path)))
+ (boolean (re-matches #"(https?:)?//.*" path)))
(defn route-compile
"Compile a path string using the routes syntax into a uri-matcher struct."
@@ -131,6 +131,7 @@
(apply str
(lex path
splat "(.*?)"
+ #"^//" "https?://"
word #(str "(" (word-regex %) ")")
literal #(re-escape (.group ^Matcher %)))))
(remove nil?
View
@@ -74,7 +74,17 @@
"http://localhost/"
{:scheme :http
:headers {"host" "localhost"}
- :uri "/"})))
+ :uri "/"}))
+ (is (route-matches
+ "//localhost/"
+ {:scheme :http
+ :headers {"host" "localhost"}
+ :uri "/"}))
+ (is (route-matches
+ "//localhost/"
+ {:scheme :https
+ :headers {"host" "localhost"}
+ :uri "/"})))
(deftest url-port-paths
(let [req (request :get "http://localhost:8080/")]

0 comments on commit ac93602

Please sign in to comment.