From 49bb9009006b87d08407e4b467852ead19ea9444 Mon Sep 17 00:00:00 2001 From: Martino Visintin Date: Tue, 18 Jun 2024 10:24:43 +0200 Subject: [PATCH] Fix mu/get-in for false-y keys --- src/malli/util.cljc | 7 ++++--- test/malli/util_test.cljc | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/malli/util.cljc b/src/malli/util.cljc index 8a7ed130f..857d3f205 100644 --- a/src/malli/util.cljc +++ b/src/malli/util.cljc @@ -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 diff --git a/test/malli/util_test.cljc b/test/malli/util_test.cljc index 6e4f8ea34..e0a8c7522 100644 --- a/test/malli/util_test.cljc +++ b/test/malli/util_test.cljc @@ -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))