formic icon indicating copy to clipboard operation
formic copied to clipboard

merge algorithm output depends on input key order

Open sheppard opened this issue 10 years ago • 1 comments

It looks like the algorithm for merging conflicting usages will produce different results depending on key order:

<form enctype='application/json'>
  <input name='mix' value='scalar'>
  <input name='mix[0]' value='array 1'>
  <input name='mix[key]' value='key key'>
</form>

produces

{
    "mix":  {
        "":     "scalar"
    ,   "0":    "array 1"
    ,   "key":  "key key"
    }
}

But:

<form enctype='application/json'>
  <input name='mix[0]' value='array 1'>
  <input name='mix' value='scalar'>
  <input name='mix[key]' value='key key'>
</form>

produces

{
    "mix":  {
        "0":    "array 1"
    ,   "1":     "scalar"
    ,   "key":  "key key"
    }
}

This is probably fine when relying on the DOM order on the client, but on the server it can produce seemingly random inconsistencies when using dictionary / hash structures with arbitrary key ordering.

Should the spec be updated to handle this situation?

sheppard avatar Mar 20 '15 18:03 sheppard

I came across this when implementing unit tests for Example 7 in Python:

https://github.com/tomchristie/django-rest-framework/pull/2682

sheppard avatar Mar 20 '15 18:03 sheppard