Skip to content

Commit

Permalink
keyword-params ignores parameters that cannot be keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Oct 2, 2011
1 parent b6aaae1 commit 9841dfd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion ring-core/src/ring/middleware/keyword_params.clj
@@ -1,11 +1,14 @@
(ns ring.middleware.keyword-params
"Convert param keys to keywords.")

(defn- keyword-syntax? [s]
(re-matches #"[A-Za-z*+!_?-][A-Za-z0-9*+!_?-]*" s))

(defn- keyify-params [target]
(cond
(map? target)
(into {}
(for [[k v] target]
(for [[k v] target :when (keyword-syntax? k)]
[(keyword k) (keyify-params v)]))
(vector? target)
(vec (map keyify-params target))
Expand Down
4 changes: 3 additions & 1 deletion ring-core/test/ring/middleware/test/keyword_params.clj
Expand Up @@ -11,4 +11,6 @@
{"foo" "bar" "biz" [{"bat" "one"} {"bat" "two"}]}
{:foo "bar" :biz [{:bat "one"} {:bat "two"}]}
{"foo" 1}
{:foo 1}))
{:foo 1}
{"foo" 1 "1bar" 2 "baz*" 3 "quz-buz" 4 "biz.bang" 5}
{:foo 1 :baz* 3 :quz-buz 4}))

0 comments on commit 9841dfd

Please sign in to comment.