diff --git a/CHANGELOG.md b/CHANGELOG.md index 05ef96f0d..8097bb832 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ We use [Break Versioning][breakver]. The version numbers follow a `.double [x] (if (string? x) - (try #?(:clj (Double/parseDouble x) - :cljs (let [x' (js/parseFloat x)] (if (js/isNaN x') x x'))) - (catch #?(:clj Exception, :cljs js/Error) _ x)) + (or (parse-double x) x) x)) (defn -number->double [x] diff --git a/test/malli/transform_test.cljc b/test/malli/transform_test.cljc index eeffb58de..d4edc96d8 100644 --- a/test/malli/transform_test.cljc +++ b/test/malli/transform_test.cljc @@ -40,6 +40,7 @@ (is (= 1.0 (mt/-string->double "1"))) (is (= 1.0 (mt/-string->double 1.0))) (is (= 1 (mt/-string->double 1))) + (is (= "1.0abba" (mt/-string->double "1.0abba"))) (is (= "abba" (mt/-string->double "abba")))) (deftest string->keyword @@ -134,6 +135,7 @@ (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))) + (is (= "1.0x" (m/decode double? "1.0x" mt/string-transformer))) (is (= :user/kikka (m/decode keyword? "user/kikka" mt/string-transformer)))) (testing "encode" (is (= "1" (m/encode int? 1 mt/string-transformer)))