Added support for scheme-relative URLs. #7

Merged
merged 1 commit into from Jun 22, 2012
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
@@ -111,9 +111,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."
@@ -130,6 +130,7 @@
(apply str
(lex path
splat "(.*?)"
+ #"^//" "https?://"
word #(str "(" (word-regex %) ")")
literal #(re-escape (.group %)))))
(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/")]