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

Nested map encoding #19

Closed
hosiawak opened this issue Mar 5, 2018 · 4 comments
Closed

Nested map encoding #19

hosiawak opened this issue Mar 5, 2018 · 4 comments

Comments

@hosiawak
Copy link

hosiawak commented Mar 5, 2018

This library doesn't handle nested maps in a format that can be later decoded with form-decode, eg.:

(ring.util.codec/form-encode {:a {:b 1 :c 2}}) ;; "a=b=1&c=2"

(ring.util.codec/form-decode "a=b=1&c=2") ;; {"a" "b=1", "c" "2"}

Specifically it should handle nested params in such a way that it is then parseable by ring.middleware.nested-params eg.:

(ring.util.codec/form-decode "a%5Bb%5D=1&a%5Bc%5D=2") ;; {"a[b]" "1", "a[c]" "2"}

(ring.middleware.nested-params/nested-params-request {:params {"a[b]" "1" "a[c]" "2"}}) ;; {:params {"a" {"b" "1", "c" "2"}}}

Is this something we could fix ?

@weavejester
Copy link
Member

The form-encode and form-decode functions are designed to encode and decode data in the application/x-www-form-urlencoded format. The format used by the nested-params middleware is a custom format on top of that. If you want functions to encode/decode in the format of the nested-params middleware, then the functions should be placed in the nested-params middleware namespace.

The first example you give should probably either raise an error or put the edn-encoded map in, instead.

@devurandom
Copy link

This would be a very useful addition. Could it be implemented by adding an optional flag to ring.util.codec/form-encode?

The first example you give should probably either raise an error or put the edn-encoded map in, instead.

In version 1.2.0 this does not raise an error:

(require 'ring.util.codec)
;=> nil
(ring.util.codec/form-encode {:a {:b 2}})
;=> "a=b=2"

Should this issue be reopened?

@weavejester
Copy link
Member

I think open a separate issue, one specifically for better handling the error caused by nested maps.

@devurandom
Copy link

I think open a separate issue, one specifically for better handling the error caused by nested maps.

Done: #42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants