Skip to content

Nested map encoding #19

Closed
Closed

Description

@hosiawak

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 ?

Activity

  1. weavejester commented on Mar 5, 2018

    @weavejester
    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.

  2. devurandom commented on Apr 28, 2023

    @devurandom

    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?

  3. weavejester commented on Apr 28, 2023

    @weavejester
    Member

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

  4. devurandom commented on May 1, 2023

    @devurandom

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions