Skip to content

Commit

Permalink
Merge branch 'master' into multi-keyword-dispatch-gen
Browse files Browse the repository at this point in the history
  • Loading branch information
ikitommi authored Aug 27, 2024
2 parents 0ab3e9b + 7d64597 commit 0bc3fa4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Malli is in well matured [alpha](README.md#alpha).
* 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` [#1090](https://github.com/metosin/malli/pull/1090)
* `:multi` with keyword `:dispatch` accumulates data to generated values [#1095](https://github.com/metosin/malli/pull/1095)
* 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 0bc3fa4

Please sign in to comment.