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" :description "Forms hiccup style"
:url "https://gitea.heevyis.ninja/josha/formulare.git" :url "https://gitea.heevyis.ninja/josha/formulare.git"
:scm {:name "git" :url "https://gitea.heevyis.ninja/josha/formulare.git"} :scm {:name "git" :url "https://gitea.heevyis.ninja/josha/formulare.git"}

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

@ -51,9 +51,9 @@
:spec nil? :spec nil?
:required false}}}] :required false}}}]
(is (= true (valid? def {:params {:name nil}}))))) (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 "" (let [def {:fields {:foo {:label ""
:spec number? :spec string?
:from-req bigint} :from-req bigint}
:bar {:label "" :bar {:label ""
:spec string?}}}] :spec string?}}}]

Loading…
Cancel
Save