Skip to content

Commit

Permalink
Merge pull request #1097 from metosin/fix-1096
Browse files Browse the repository at this point in the history
fix #1096
  • Loading branch information
ikitommi authored Aug 27, 2024
2 parents 6dd2a9d + 5747e9a commit 7d64597
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
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
9 changes: 5 additions & 4 deletions src/malli/error.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,11 @@
(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)
(set? x) (cond-> y (not= (count x) (count y)) (conj mask))
(sequential? x) (-fill y (count x) mask)
:else y))
(let [nested (and (map? x) (or (map? y) (nil? y)))]
(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)
(set? x) (cond-> y (not= (count x) (count y)) (conj mask))
(sequential? x) (-fill y (count x) mask)
:else y)))

;;
;; spell checking (kudos to https://github.com/bhauman/spell-spec)
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 7d64597

Please sign in to comment.