Skip to content

Commit

Permalink
check for infinitely expanding schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Jul 16, 2024
1 parent 0dd2e0d commit 4d44b60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@
(defn- -lookup [?schema options]
(let [registry (-registry options)]
(or (mr/-schema registry ?schema)
(some-> registry (mr/-schema (c/type ?schema)) (-into-schema nil [?schema] options)))))
(when-some [p (some-> registry (mr/-schema (c/type ?schema)))]
(when (schema? ?schema)
(when (= p (-parent ?schema))
(-fail! ::infinitely-expanding-schema {:schema ?schema})))
(-into-schema p nil [?schema] options)))))

(defn- -lookup! [?schema ?form f rec options]
(or (and f (f ?schema) ?schema)
Expand Down
6 changes: 6 additions & 0 deletions test/malli/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3372,3 +3372,9 @@
:errors [{:path [::m/in :y], :in [:y], :schema y-schema, :value "2"}]}
explain))
(is (form= y-schema (mu/get-in schema (-> explain :errors first :path))))))

(deftest catch-infinitely-expanding-schema
(is (thrown-with-msg?
#?(:clj Exception, :cljs js/Error)
#":malli\.core/infinitely-expanding-schema"
(m/schema [(m/schema :any)]))))

0 comments on commit 4d44b60

Please sign in to comment.