Skip to content

Commit

Permalink
Merge pull request #392 from metosin/support_nil_map_keys
Browse files Browse the repository at this point in the history
support nil keys in maps
  • Loading branch information
ikitommi authored Mar 11, 2021
2 parents b4f4e0b + 397c233 commit b8c4098
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@
(-reference? e) (if naked-keys [[e nil e] e])
(and (= 2 (count e)) (-reference? (first e)) (map? (last e))) (if naked-keys [(conj e (first e)) e])
:else [e (->> (-update (vec e) (dec (count e)) (-comp -form #(schema % options))) (keep identity) (vec))])
_ (when (nil? k) (miu/-fail! ::naked-keys-not-supported))
[p ?s] (if (or (nil? ?p) (map? ?p)) [?p ?v] [nil ?p])
s (cond-> (or ?s (if (-reference? k) f)) lazy-refs (-lazy options))
c [k p (schema s options)]]
Expand Down
12 changes: 12 additions & 0 deletions test/malli/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,18 @@
(is (true? (m/validate [:map [:b boolean?]] {:b false})))
(is (true? (m/validate [:map [:n nil?]] {:n nil}))))

(testing "nil keys"
(is (true? (m/validate
[:map
["status" [:enum "ok"]]
[1 any?]
[nil any?]
[::a string?]]
{"status" "ok"
1 'number
nil :yay
::a "properly awesome"}))))

(testing "accumulating errors #84"
(let [re #"b"
schema [:map
Expand Down

0 comments on commit b8c4098

Please sign in to comment.