Updated massage-params to use params when form-params are not present.

This commit is contained in:
Simon Brooke 2018-07-27 09:10:28 +01:00
parent e17a79e7c7
commit 3e64062dcc

View file

@ -70,32 +70,36 @@
(defn raw-massage-params (defn raw-massage-params
"Sending empty strings, or numbers as strings, to the database often isn't "Sending empty strings, or numbers as strings, to the database often isn't
helpful. Massage these `params` and `form-params` to eliminate these problems. helpful. Massage these `params` and `form-params` to eliminate these problems.
We must take key field values out of just params, but we should take all other We must take key field values out of just params, but if form-params are present
values out of form-params - because we need the key to load the form in we should take all other values out of form-params - because we need the key to
the first place, but just accepting values of other params would allow spoofing." load the form in the first place. `form-params` always override `params`"
([params form-params key-fields] ([params form-params key-fields]
(let (let
[ks (set (map keyword key-fields))] [ks (set (map keyword key-fields))
(reduce p (reduce
merge merge
;; do the keyfields first, from params {}
(reduce (map
merge #(massage-value % params)
{} (filter
(map #(ks (keyword %))
#(massage-value % params) (keys params))))]
(filter (if
#(ks (keyword %)) (empty? form-params)
(keys params)))) p
;; then merge in everything from form-params, potentially overriding what (reduce
;; we got from params. merge
(map ;; do the keyfields first, from params
#(massage-value % form-params) p
(keys form-params))))) ;; then merge in everything from form-params, potentially overriding what
([request key-fields] ;; we got from params.
(raw-massage-params (:params request) (:form-params request) key-fields)) (map
([request] #(massage-value % form-params)
(raw-massage-params (:params request) (:form-params request) #{}))) (keys form-params))))))
([request key-fields]
(raw-massage-params (:params request) (:form-params request) key-fields))
([request]
(raw-massage-params (:params request) (:form-params request) #{})))
(def massage-params (def massage-params