Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support nil keys in maps #392

Merged
merged 1 commit into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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