Skip to content

Commit 7d64597

Browse files
authored
Merge pull request #1097 from metosin/fix-1096
fix #1096
2 parents 6dd2a9d + 5747e9a commit 7d64597

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Malli is in well matured [alpha](README.md#alpha).
1919
* Fix ClojureScript [arithmetic warning](https://github.com/metosin/malli/issues/1093)
2020
* Distribute `:merge` over `:multi` [#1086](https://github.com/metosin/malli/pull/1086), see [documentation](README.md#distributive-schemas)
2121
* allow `m/-proxy-schema` child to be a `delay`
22+
* Fix `malli.dev.pretty` throws when explaining errors in nested maps [#1094](https://github.com/metosin/malli/issues/1096)
2223

2324
## 0.16.3 (2024-08-05)
2425

src/malli/error.cljc

+5-4
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,11 @@
193193
(reduce (fn [acc error] (cond-> acc (accept error) (-replace-in value (:in error) (wrap error) mask))) acc errors)))
194194

195195
(defn -masked [mask x y]
196-
(cond (map? x) (reduce-kv (fn [acc k v] (let [e (find y k)] (assoc acc k (if e (-masked mask v (val e)) mask)))) y x)
197-
(set? x) (cond-> y (not= (count x) (count y)) (conj mask))
198-
(sequential? x) (-fill y (count x) mask)
199-
:else y))
196+
(let [nested (and (map? x) (or (map? y) (nil? y)))]
197+
(cond nested (reduce-kv (fn [acc k v] (let [e (find y k)] (assoc acc k (if e (-masked mask v (val e)) mask)))) y x)
198+
(set? x) (cond-> y (not= (count x) (count y)) (conj mask))
199+
(sequential? x) (-fill y (count x) mask)
200+
:else y)))
200201

201202
;;
202203
;; spell checking (kudos to https://github.com/bhauman/spell-spec)

test/malli/error_test.cljc

+5
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,11 @@
758758
(for [error (:errors explain)]
759759
(me/error-value (assoc explain :errors [error]) {::me/mask-valid-values '...}))))))
760760

761+
(testing "masked nested maps #1096"
762+
(is (= {"foo" "foo"}
763+
(-> (m/explain [:map-of :keyword [:map-of :keyword :any]] {"foo" {:bar 1}})
764+
(me/error-value {::me/mask-valid-values '...})))))
765+
761766
(testing "custom painting of errors"
762767
(is (= {:EXTRA {:value "KEY", :type :malli.core/extra-key}
763768
:tags #{{:value "ground"} {:value "coffee"}}

0 commit comments

Comments
 (0)