From 12d5cf1a97273ce033e7f80802c99e9c7957ce60 Mon Sep 17 00:00:00 2001 From: Danny Wilson Date: Wed, 18 Nov 2015 17:32:53 +0100 Subject: [PATCH 1/2] More precise doc-strings of :params behavior --- ring-core/src/ring/middleware/params.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ring-core/src/ring/middleware/params.clj b/ring-core/src/ring/middleware/params.clj index c1ed351e..09588a3e 100644 --- a/ring-core/src/ring/middleware/params.clj +++ b/ring-core/src/ring/middleware/params.clj @@ -29,7 +29,7 @@ {:form-params {}, :params {}}))) (defn params-request - "Adds parameters from the query string and the request body to the request + "Adds parameters from the request body and the query string to the request map. See: wrap-params." {:arglists '([request] [request options]) :added "1.2"} @@ -51,7 +51,7 @@ :query-params - a map of parameters from the query string :form-params - a map of parameters from the body - :params - a merged map of all types of parameter + :params - a merged map of all types of parameter, query-params last Accepts the following options: From e7537676526c2f8a43611b2600550d4d0cbab5f3 Mon Sep 17 00:00:00 2001 From: Danny Wilson Date: Wed, 18 Nov 2015 17:33:13 +0100 Subject: [PATCH 2/2] Short-circuit nested-params when already applied or empty --- ring-core/src/ring/middleware/nested_params.clj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ring-core/src/ring/middleware/nested_params.clj b/ring-core/src/ring/middleware/nested_params.clj index 7a6abb4b..830331a8 100644 --- a/ring-core/src/ring/middleware/nested_params.clj +++ b/ring-core/src/ring/middleware/nested_params.clj @@ -58,9 +58,11 @@ See: wrap-nested-params." {:arglists '([request] [request options]) :added "1.2"} - [request & [opts]] + [{:keys [params] :as request} & [opts]] (let [parse (:key-parser opts parse-nested-keys)] - (update-in request [:params] nest-params parse))) + (if (or (empty? params) (-> params meta :nested-params)) + request + (assoc request :params ^:nested-params (nest-params params parse))))) (defn wrap-nested-params "Middleware to converts a flat map of parameters into a nested map.