Skip to content

Commit

Permalink
Merge pull request #945 from metosin/fix-937
Browse files Browse the repository at this point in the history
fix #937
  • Loading branch information
ikitommi authored Sep 2, 2023
2 parents 07cf169 + 4d15627 commit 74d1b23
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/malli/impl/regex.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,21 @@

;;;; ## Alternation

(defn alt-validator [& ?krs]
(reduce (fn [acc ?kr]
(let [r (entry->regex acc), r* (entry->regex ?kr)]
(defn alt-validator [?kr & ?krs]
(reduce (fn [r ?kr]
(let [r* (entry->regex ?kr)]
(fn [driver regs pos coll k]
(park-validator! driver r* regs pos coll k) ; remember fallback
(park-validator! driver r regs pos coll k))))
?krs))
(entry->regex ?kr) ?krs))

(defn alt-explainer [& ?krs]
(reduce (fn [acc ?kr]
(let [r (entry->regex acc), r* (entry->regex ?kr)]
(defn alt-explainer [?kr & ?krs]
(reduce (fn [r ?kr]
(let [r* (entry->regex ?kr)]
(fn [driver regs pos coll k]
(park-explainer! driver r* regs pos coll k) ; remember fallback
(park-explainer! driver r regs pos coll k))))
?krs))
(entry->regex ?kr) ?krs))

(defn alt-parser [& rs]
(reduce (fn [r r*]
Expand Down Expand Up @@ -261,13 +261,13 @@
:malli.core/invalid)
:malli.core/invalid))))

(defn alt-transformer [& ?krs]
(reduce (fn [acc ?kr]
(let [r (entry->regex acc), r* (entry->regex ?kr)]
(defn alt-transformer [?kr & ?krs]
(reduce (fn [r ?kr]
(let [r* (entry->regex ?kr)]
(fn [driver regs coll* pos coll k]
(park-transformer! driver r* regs coll* pos coll k) ; remember fallback
(park-transformer! driver r regs coll* pos coll k))))
?krs))
(entry->regex ?kr) ?krs))

;;;; ## Option

Expand Down
10 changes: 10 additions & 0 deletions test/malli/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2974,3 +2974,13 @@
[:i :int]]
input [1 2 3 4 5 6 7 8 9]]
(is (= input (->> input (m/parse schema) (m/unparse schema)))))))

(deftest -issue-937-test
(testing ":altn can handle just one child entry when nested"
(let [schema [:* [:altn [:a [:= :a]]]]
value [:a]]
(is (= true (m/validate schema value)))
(is (= nil (m/explain schema value)))
(is (= [[:a :a]] (m/parse schema value)))
(is (= value (m/unparse schema (m/parse schema value))))
(is (= value (m/decode schema value nil))))))

0 comments on commit 74d1b23

Please sign in to comment.