ngrunwald / ring-middleware-format

Ring middleware for parsing parameters and emitting responses in JSON or other formats
163 stars 49 forks source link

Don’t try to merge the body into `:params` if it’s not a map. #7

Closed ieure closed 12 years ago

ieure commented 12 years ago

The existing implementation of wrap-format-params always tries to merge :body-params into :params. However, when the request payload is a JSON list instead of a JSON object, this causes an IllegalArgumentException:

  actual: java.lang.IllegalArgumentException: Vector arg to map conj must be a pair
 at clojure.lang.APersistentMap.cons (APersistentMap.java:34)
    clojure.lang.RT.conj (RT.java:551)
    clojure.core$conj.invoke (core.clj:83)
    clojure.core$merge$fn__4155.invoke (core.clj:2631)
    clojure.core$reduce1.invoke (core.clj:880)
    clojure.core$reduce1.invoke (core.clj:871)
    clojure.core$merge.doInvoke (core.clj:2631)
    clojure.lang.RestFn.invoke (RestFn.java:421)
    ring.middleware.format_params$wrap_format_params$fn__488.invoke (format_params.clj:59)
    ring.middleware.test.format_params/fn (format_params.clj:132)

This patch only merges if the payload is a map, and adds a test. This has bitten me a couple times, and I'd really like to see an updated release which fixes it.

ngrunwald commented 12 years ago

Thanks! Merged, I'll do a release very soon...