🐛 Add missing string? guard to num-string? on JVM

The CLJS branch of num-string? checked (string? v) first, but the
JVM branch did not. Passing non-string values (nil, keywords, etc.)
would rely on exception handling inside parse-double for control
flow. Add the string? check for consistency and to avoid using
exceptions for normal control flow.
This commit is contained in:
Andrey Antukh 2026-04-14 20:18:55 +00:00 committed by Belén Albeza
parent bba3610b7b
commit 95d4d42c91
2 changed files with 5 additions and 1 deletions

View File

@ -782,7 +782,8 @@
(not (js/isNaN v))
(not (js/isNaN (parse-double v))))
:clj (not= (parse-double v :nan) :nan)))
:clj (and (string? v)
(not= (parse-double v :nan) :nan))))
(defn read-string
[v]

View File

@ -841,6 +841,9 @@
(t/is (d/num-string? "-7"))
(t/is (not (d/num-string? "hello")))
(t/is (not (d/num-string? nil)))
;; non-string types always return false
(t/is (not (d/num-string? 42)))
(t/is (not (d/num-string? :keyword)))
;; In CLJS, js/isNaN("") → false (empty string coerces to 0), so "" is numeric
#?(:clj (t/is (not (d/num-string? ""))))
#?(:cljs (t/is (d/num-string? ""))))