metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.44k stars 204 forks source link

`mt/string-transformer` is not case insensitive for UUIDs #922

Closed axvr closed 10 months ago

axvr commented 11 months ago

When given an upper case UUID string, the mt/string-transformer does not convert it to a UUID object.

(require '[malli.core :as m])
(require '[malli.transform :as mt])

(m/decode :uuid "b3c4e6b4-6304-4a52-99c3-cb50e737bb94" mt/string-transformer)
;; => #uuid "b3c4e6b4-6304-4a52-99c3-cb50e737bb94"

(m/decode :uuid "B3C4E6B4-6304-4A52-99C3-CB50E737BB94" mt/string-transformer)
;; => "B3C4E6B4-6304-4A52-99C3-CB50E737BB94"

The UUID RFC also states (emphasis mine):

Each field is treated as an integer and has its value printed as a zero-filled hexadecimal digit string with the most significant digit first. The hexadecimal values "a" through "f" are output as lower case characters and are case insensitive on input.

While generated UUIDs should be lower case as per the RFC, this is unfortunately not always the case (e.g. the uuidgen command on macOS and old Microsoft programs).

The clojure.core/parse-uuid function (and the UUID/fromString static method that backs it) are also case insensitive.

jasonjckn commented 11 months ago

I can do the PR for this... start off with something simple, for my first PR to malli. ...

Is there someone with merge authority that can comment whether they want this fixed?

ikitommi commented 10 months ago

@niwinz you have been doing UUID fixes for Malli. What do you think about this?

niwinz commented 10 months ago

Yep, I will look on on it today :D

niwinz commented 10 months ago

I think the issue is valid, and for to be RFC compliant, we need to accept uuids in case insensitive way. I created a PR for address this.