From 90cd5ddb6d992ba8e161b9e2e0d16602b589db39 Mon Sep 17 00:00:00 2001 From: Paul Iannazzo Date: Sun, 8 Sep 2019 21:35:23 -0400 Subject: [PATCH] Fix - Impossible to receive multipart/form-data with multiple parts having the same name Fix for issue #277 Now accumulate parts with same name in a vector. --- ext/multipart/src/yada/multipart.clj | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ext/multipart/src/yada/multipart.clj b/ext/multipart/src/yada/multipart.clj index 7df98b6a..b93afe13 100644 --- a/ext/multipart/src/yada/multipart.clj +++ b/ext/multipart/src/yada/multipart.clj @@ -646,9 +646,16 @@ ;; Content-Disposition headers. (let [schemas (get-in ctx [:resource :methods (:method ctx) :parameters]) parts-by-name (reduce - (fn [acc part] (cond-> acc - (= (:type part) :part) - (assoc (get-in part [:content-disposition :params "name"]) part))) + (fn [acc part] + (let [name (get-in part [:content-disposition :params "name"]) + [_ already-occupied?] (find acc name) + result (case [(= (:type part) :part) (not (nil? already-occupied?)) (vector? already-occupied?)] + [true true true] (update acc name conj part) + [true true false] (assoc acc name [already-occupied? part]) + [true false false] (assoc acc name part) + [false false false] acc + )] + result)) {} parts)] (cond->