diff --git a/src/malli/transform.cljc b/src/malli/transform.cljc index 2dd4673a4..eb3b7fc4f 100644 --- a/src/malli/transform.cljc +++ b/src/malli/transform.cljc @@ -82,7 +82,9 @@ (if (string? x) (try #?(:clj (Long/parseLong x) - :cljs (let [x' (js/parseInt x 10)] + :cljs (let [x' (if (re-find #"\D" (subs x 1)) + ##NaN + (js/parseInt x 10))] (if (js/isNaN x') x x'))) (catch #?(:clj Exception, :cljs js/Error) _ x)) x)) diff --git a/test/malli/transform_test.cljc b/test/malli/transform_test.cljc index b3e2ad5e6..16ca6f13a 100644 --- a/test/malli/transform_test.cljc +++ b/test/malli/transform_test.cljc @@ -97,6 +97,10 @@ (testing "predicates" (testing "decode" (is (= 1 (m/decode int? "1" mt/string-transformer))) + (is (= "1abc" (m/decode int? "1abc" mt/string-transformer))) + (is (= "+1-2" (m/decode int? "+1-2" mt/string-transformer))) + (is (= 1 (m/decode int? "+1" mt/string-transformer))) + (is (= -1 (m/decode int? "-1" mt/string-transformer))) (is (= "1" (m/decode int? "1" mt/json-transformer))) (is (= 1.0 (m/decode double? 1 mt/json-transformer))) (is (= 1 (m/decode double? 1 mt/string-transformer)))