Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: -string->double for cljs shouldn't allow trailing garbage #942

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ We use [Break Versioning][breakver]. The version numbers follow a `<major>.<mino

Malli is in well matured [alpha](README.md#alpha).

## Unreleased

* **BREAKING**: `decode` for `:double` and `double?` in cljs doesn't allow trailing garbage any more [#942](https://github.com/metosin/malli/pull/942)

## 0.12.0 (2023-08-31)

* FIX: retain order with `:catn` unparse, fixes [#925](https://github.com/metosin/malli/issues/925)
Expand Down
4 changes: 1 addition & 3 deletions src/malli/transform.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@

(defn -string->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]
Expand Down
2 changes: 2 additions & 0 deletions test/malli/transform_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down