ring-clojure / ring-codec

Utility library for encoding and decoding data
MIT License
63 stars 30 forks source link

ring.util.codec/FormEncodeable impl for nil #3

Closed tomoharu-fujita closed 6 years ago

tomoharu-fujita commented 10 years ago

form-encode fails to encode if nil value is in map:

user=> (require '[ring.util.codec :as codec]) user=> (codec/form-encode (codec/form-decode "a&b=1")) IllegalArgumentException No implementation of method: :form-encode* of protocol: #'ring.util.codec/FormEncodeable found for class: nil clojure.core/-cache-protocol-fn (core_deftype.clj:541)

It would be nicer if nil value treated as is.

user=> (extend-type nil

_=> codec/FormEncodeable

=> (form-encode* [ _] ""))

nil user=> (codec/form-encode (codec/form-decode "a&b=1")) "b=1&a="

mping commented 10 years ago

Any news on this?

weavejester commented 10 years ago

Since Object is encoded, it seems reasonable to encode nil as a blank string.

However, I'm not sure that a&b=1 should be decoded as {:a nil :b "1"}. It should probably raise an error instead.

weavejester commented 9 years ago

@buob: The exception is likely is likely caused by (:id user) or (:auth-token user) being nil.

weavejester commented 6 years ago

Fixed by #18