File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616 (:use compojure.str-utils)
1717 (:use compojure.map-utils)
1818 (:use compojure.control)
19+ (:use compojure.encodings)
1920 (:import java.util.regex.Pattern)
2021 (:import java.util.Map))
2122
9596 (reduce
9697 (fn [m [k v]] (assoc-vec m k v))
9798 {}
98- (map vector keywords ( rest groups) )))
99+ (map vector keywords groups)))
99100
100101(defmulti match-uri
101102 " Match a URL against a compiled URI-matcher or a regular expression. Returns
107108 (let [matcher (re-matcher (uri-matcher :regex ) (or uri " /" ))]
108109 (if (.matches matcher)
109110 (assoc-keywords-with-groups
110- (re-groups matcher)
111+ (map urldecode ( re-groups* matcher) )
111112 (uri-matcher :keywords )))))
112113
113114(defmethod match-uri Pattern
114115 [uri-pattern uri]
115116 (let [matches (re-matches uri-pattern (or uri " /" ))]
116117 (if matches
117118 (if (vector? matches)
118- (subvec matches 1 )
119+ (vec ( map urldecode ( rest matches)) )
119120 []))))
120121
121122(defn match-method
Original file line number Diff line number Diff line change 5252 [string]
5353 (escape " \\ .*+|?()[]{}$^" string))
5454
55+ (defn re-groups*
56+ " More consistant re-groups that always returns a vector of groups, even if
57+ there is only one group."
58+ [matcher]
59+ (for [i (range (.groupCount matcher))]
60+ (.group matcher (inc i))))
61+
5562(defn blank?
5663 " True if s = \"\" or nil"
5764 [s]
Original file line number Diff line number Diff line change 3030 " /:foo-bar" " /baz" {:foo-bar " baz" }
3131 " /:foo-" " /baz" {:foo- " baz" }))
3232
33+ (deftest urlencoded-keywords
34+ (are (= (match-uri (compile-uri-matcher _1) _2) _3)
35+ " /:x" " /foo%20bar" {:x " foo bar" }
36+ " /:x" " /foo+bar" {:x " foo bar" }))
37+
3338(deftest same-keyword-many-times
3439 (are (= (match-uri (compile-uri-matcher _1) _2) _3)
3540 " /:x/:x/:x" " /a/b/c" {:x [" a" " b" " c" ]}
You can’t perform that action at this time.
0 commit comments