Skip to content

Commit

Permalink
Fixed parameter-parsing issue with non-UTF8-encoded data
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Dec 2, 2011
1 parent 74381d1 commit 8cd85cf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ring-core/src/ring/middleware/params.clj
Expand Up @@ -47,7 +47,7 @@
[request encoding] [request encoding]
(merge-with merge request (merge-with merge request
(if-let [body (and (urlencoded-form? request) (:body request))] (if-let [body (and (urlencoded-form? request) (:body request))]
(let [params (parse-params (slurp body) encoding)] (let [params (parse-params (slurp body :encoding encoding) encoding)]
{:form-params params, :params params}) {:form-params params, :params params})
{:form-params {}, :params {}}))) {:form-params {}, :params {}})))


Expand Down
9 changes: 6 additions & 3 deletions ring-core/src/ring/util/test.clj
@@ -1,7 +1,10 @@
(ns ring.util.test (ns ring.util.test
"Utilities for testing Ring components." "Utilities for testing Ring components."
(:import (java.io ByteArrayInputStream))) (:import java.io.ByteArrayInputStream))


(defn string-input-stream [^String s] (defn string-input-stream
"Returns a ByteArrayInputStream for the given String." "Returns a ByteArrayInputStream for the given String."
(ByteArrayInputStream. (.getBytes s))) ([^String s]
(ByteArrayInputStream. (.getBytes s)))
([^String s encoding]
(ByteArrayInputStream. (.getBytes s encoding))))
8 changes: 8 additions & 0 deletions ring-core/test/ring/middleware/test/params.clj
Expand Up @@ -36,3 +36,11 @@
(is (= {} (:query-params resp))) (is (= {} (:query-params resp)))
(is (= {} (:form-params resp))) (is (= {} (:form-params resp)))
(is (= {} (:params resp))))) (is (= {} (:params resp)))))

(deftest wrap-params-encoding
(let [req {:character-encoding "UTF-16"
:content-type "application/x-www-form-urlencoded"
:body (tu/string-input-stream "hello=world" "UTF-16")}
resp (wrapped-echo req)]
(is (= (:params resp) {"hello" "world"}))
(is (= (:form-params resp) {"hello" "world"}))))

0 comments on commit 8cd85cf

Please sign in to comment.