diff --git a/src/malli/core.cljc b/src/malli/core.cljc index 6cdd31ae4..8808e22f2 100644 --- a/src/malli/core.cljc +++ b/src/malli/core.cljc @@ -560,8 +560,8 @@ (let [x* (transformer x)] (if ((nth validators i) x*) (reduced x*) - (or acc x*)))) - nil transformers)) + (if (-equals acc ::nil) x* acc)))) + ::nil transformers)) (fn [x] (reduce-kv (fn [x i validator] (if (validator x) (reduced ((nth transformers i) x)) x)) diff --git a/test/malli/core_test.cljc b/test/malli/core_test.cljc index 367a1867f..2ef6fba5b 100644 --- a/test/malli/core_test.cljc +++ b/test/malli/core_test.cljc @@ -319,7 +319,15 @@ :string] 1 math) (m/decode [:orn ["kw-math" math-kw-string] - ["string" :string]] 1 math))))) + ["string" :string]] 1 math)))) + + (testing "first branch nil can be selected as a fallback" + (is (= nil (m/decode + [:or + [:keyword {:decode/math (constantly nil)}] + :keyword] + "kikka" + (mt/transformer {:name :math})))))) (testing "top-level transformations are retained" (doseq [schema [[:or {:decode/string {:enter (fn [m] (update m :enter #(or % true)))