Skip to content

Commit

Permalink
fix #1096
Browse files Browse the repository at this point in the history
  • Loading branch information
ikitommi committed Aug 27, 2024
1 parent 6dd2a9d commit 0d30c16
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Malli is in well matured [alpha](README.md#alpha).
* Fix ClojureScript [arithmetic warning](https://github.com/metosin/malli/issues/1093)
* Distribute `:merge` over `:multi` [#1086](https://github.com/metosin/malli/pull/1086), see [documentation](README.md#distributive-schemas)
* allow `m/-proxy-schema` child to be a `delay`
* Fix `malli.dev.pretty` throws when explaining errors in nested maps [#1094](https://github.com/metosin/malli/issues/1096)

## 0.16.3 (2024-08-05)

Expand Down
2 changes: 1 addition & 1 deletion src/malli/error.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
(reduce (fn [acc error] (cond-> acc (accept error) (-replace-in value (:in error) (wrap error) mask))) acc errors)))

(defn -masked [mask x y]
(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)
(cond (and (map? x) (or (nil? y) (map? y))) (reduce-kv (fn [acc k v] (let [e (find y k)] (assoc acc k (if e (-masked mask v (val e)) mask)))) y x)
(set? x) (cond-> y (not= (count x) (count y)) (conj mask))
(sequential? x) (-fill y (count x) mask)
:else y))
Expand Down
5 changes: 5 additions & 0 deletions test/malli/error_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,11 @@
(for [error (:errors explain)]
(me/error-value (assoc explain :errors [error]) {::me/mask-valid-values '...}))))))

(testing "masked nested maps #1096"
(is (= {"foo" "foo"}
(-> (m/explain [:map-of :keyword [:map-of :keyword :any]] {"foo" {:bar 1}})
(me/error-value {::me/mask-valid-values '...})))))

(testing "custom painting of errors"
(is (= {:EXTRA {:value "KEY", :type :malli.core/extra-key}
:tags #{{:value "ground"} {:value "coffee"}}
Expand Down

0 comments on commit 0d30c16

Please sign in to comment.