Skip to content
Browse files

Fixed parameter-parsing issue with non-UTF8-encoded data

  • Loading branch information...
1 parent 74381d1 commit 8cd85cf9d9d6cb494484c6b5a55ca3c38d7dc810 @weavejester weavejester committed Dec 2, 2011
View
2 ring-core/src/ring/middleware/params.clj
@@ -47,7 +47,7 @@
[request encoding]
(merge-with merge 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 {}})))
View
9 ring-core/src/ring/util/test.clj
@@ -1,7 +1,10 @@
(ns ring.util.test
"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."
- (ByteArrayInputStream. (.getBytes s)))
+ ([^String s]
+ (ByteArrayInputStream. (.getBytes s)))
+ ([^String s encoding]
+ (ByteArrayInputStream. (.getBytes s encoding))))
View
8 ring-core/test/ring/middleware/test/params.clj
@@ -36,3 +36,11 @@
(is (= {} (:query-params resp)))
(is (= {} (:form-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.
Something went wrong with that request. Please try again.