fix possible nullpointer, unconcerted values are passed to specs

master
Josha von Gizycki 6 years ago
parent 53d95a5ea7
commit 96f2482724

@ -1,4 +1,4 @@
(defproject joshavg/formulare "0.3.2-SNAPSHOT"
(defproject joshavg/formulare "0.3.3-SNAPSHOT"
:description "Forms hiccup style"
:url "https://gitea.heevyis.ninja/josha/formulare.git"
:scm {:name "git" :url "https://gitea.heevyis.ninja/josha/formulare.git"}

@ -54,11 +54,11 @@
true
(:form-specs form-def)))
(defn field-specs-valid? [form-def data]
(defn field-specs-valid? [form-def req]
(reduce-kv
(fn [result field field-def]
(if-let [field-spec (:spec field-def)]
(if (spec/valid? field-spec (field data))
(if (spec/valid? field-spec (get-in req [:params field]))
true
(reduced false))
result))
@ -68,7 +68,7 @@
(defn valid? [form-def req]
{:pre [(spec/assert ::form form-def)]}
(let [data (form-data form-def req)]
(and (field-specs-valid? form-def data)
(and (field-specs-valid? form-def req)
(form-specs-valid? form-def req))))
(def ^:dynamic *row-theme* theme/row)
@ -93,7 +93,9 @@
:mselect *mselect-widget-theme*
:hidden *hidden-widget-theme*
*input-widget-theme*)]
(*row-theme* (when (and validate? (not (spec/valid? spec req-value)))
(*row-theme* (when (and validate?
spec
(not (spec/valid? spec req-value)))
(*widget-error-theme* id def req-value))
(*label-theme* id def)
(renderer id def (if validate? req-value value)))))

@ -51,9 +51,9 @@
:spec nil?
:required false}}}]
(is (= true (valid? def {:params {:name nil}})))))
(testing "converted values are passed to spec"
(testing "unconverted values are passed to spec"
(let [def {:fields {:foo {:label ""
:spec number?
:spec string?
:from-req bigint}
:bar {:label ""
:spec string?}}}]

Loading…
Cancel
Save