Permalink
Browse files

'+' no longer decoded as space in URI paths (fixes #5)

  • Loading branch information...
1 parent b3d9114 commit 6ce6b967d7eac2b71a25075b68cc8b93c14bd01c @weavejester weavejester committed Nov 20, 2011
Showing with 11 additions and 6 deletions.
  1. +10 −5 src/clout/core.clj
  2. +1 −1 test/clout/test/core.clj
View
@@ -25,10 +25,15 @@
;; Route matching
-(defn- urldecode
- "Encode a urlencoded string using the default encoding."
- [string]
- (URLDecoder/decode string "UTF-8"))
+(defn path-decode
+ "Decode a path segment in a URI. Defaults to using UTF-8 encoding."
+ ([path]
+ (path-decode path "UTF-8"))
+ ([path encoding]
+ (string/replace
+ path
+ #"(?:%[0-9A-Fa-f]{2})+"
+ #(URLDecoder/decode % encoding))))
(defn- assoc-vec
"Associate a key with a value. If the key already exists in the map, create a
@@ -78,7 +83,7 @@
matcher (re-matcher re path-info)]
(if (.matches matcher)
(assoc-keys-with-groups
- (map urldecode (re-groups* matcher))
+ (map path-decode (re-groups* matcher))
keys)))))
;; Compile routes
View
@@ -35,7 +35,7 @@
(deftest urlencoded-keywords
(are [path uri params] (= (route-matches path (request :get uri)) params)
"/:x" "/foo%20bar" {:x "foo bar"}
- "/:x" "/foo+bar" {:x "foo bar"}))
+ "/:x" "/foo+bar" {:x "foo+bar"}))
(deftest same-keyword-many-times
(are [path uri params] (= (route-matches path (request :get uri)) params)

0 comments on commit 6ce6b96

Please sign in to comment.