Permalink
Browse files

Duplicate multipart parameters handled corrected (fixes #37)

  • Loading branch information...
1 parent 8b0dd7d commit 61eb961f42f61209dfc207847391c531a7448db9 @weavejester weavejester committed Oct 10, 2011
@@ -50,11 +50,14 @@
(defn- parse-multipart-params
"Parse a map of multipart parameters from the request."
[request encoding store]
- (into {}
- (for [^FileItemStream item (file-item-seq
- (request-context request encoding))]
- [(.getFieldName item)
- (parse-file-item item store)])))
+ (reduce
+ (fn [params item]
+ (assoc-param params
+ (.getFieldName item)
+ (parse-file-item item store)))
+ {}
+ (file-item-seq
+ (request-context request encoding))))
(defn- load-var
"Returns the var named by the supplied symbol, or nil if not found. Attempts
@@ -31,3 +31,21 @@
(is (= (:filename upload) "test.txt"))
(is (= (:content-type upload) "text/plain"))
(is (= (:content upload) "foo")))))
+
+(deftest test-multiple-params
+ (let [form-body (str "--XXXX\r\n"
+ "Content-Disposition: form-data;"
+ "name=\"foo\"\r\n\r\n"
+ "bar\r\n"
+ "--XXXX\r\n"
+ "Content-Disposition: form-data;"
+ "name=\"foo\"\r\n\r\n"
+ "baz\r\n"
+ "--XXXX--")
+ handler (wrap-multipart-params identity {:store string-store})
+ request {:content-type "multipart/form-data; boundary=XXXX"
+ :content-length (count form-body)
+ :body (string-input-stream form-body)}
+ response (handler request)]
+ (is (= (get-in response [:params "foo"])
+ ["bar" "baz"]))))

0 comments on commit 61eb961

Please sign in to comment.