Skip to content

Commit

Permalink
Merge pull request #1065 from vise890/false-dispatch-value
Browse files Browse the repository at this point in the history
Fix mu/get-in for false-y keys
  • Loading branch information
ikitommi authored Jun 18, 2024
2 parents 8f60ac7 + 49bb900 commit 666757d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/malli/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,12 @@
(get-in ?schema ks nil nil))
([?schema ks default]
(get-in ?schema ks default nil))
([?schema [k & ks] default options]
([?schema ks default options]
(let [schema (m/schema (or ?schema :map) options)]
(if-not k
(if-not (seq ks)
schema
(let [sentinel #?(:clj (Object.), :cljs (js-obj))
(let [[k & ks] ks
sentinel #?(:clj (Object.), :cljs (js-obj))
schema (get schema k sentinel)]
(cond
(identical? schema sentinel) default
Expand Down
6 changes: 6 additions & 0 deletions test/malli/util_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@
[:x 0 0 0 1 :y 9]
pos-int?)
pos-int?))
(is (mu/equals (mu/get-in
[:multi {:dispatch :x}
[true [:map [:x :boolean]]]
[false [:map [:x :boolean] [:y :boolean]]]]
[false])
[:map [:x :boolean] [:y :boolean]]))
(is (mu/equals [:maybe [:tuple int? boolean?]]
(mu/get-in (m/schema [:maybe [:tuple int? boolean?]]) [])))
(is (form= (mu/get-in (m/schema [:ref {:registry {::a int?, ::b string?}} ::a]) [0]) ::a))
Expand Down

0 comments on commit 666757d

Please sign in to comment.