Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Think that's fair point, yup. Very easy to do unintentionally, and it's non-intuitive that it'll suddenly change the return type.

It's not clear if this style is really necessary. Why not just use the indexed syntax in this case?

I guess it may be the authors intention to mirror form encoded submissions, that would send all of these values to the server.

I'd suggest raising the point on the issue tracker so that it at least gets sufficient design discussion.

https://github.com/darobin/formic/issues



Well, the safe way would be to mirror the current form spec and treat everything as arrays of strings by default.

    <form enctype='application/json'>
      <input type='text' name='fruit' value='apple'>
      <input type='number' name='bottle-on-wall' value='1'>
      <input type='number' name='bottle-on-wall' value='2'>
      <input type='number' name='bottle-on-wall' value='3'>
    </form>


    {
      "fruit": ["apple"],
      "bottle-on-wall": ["1", "2", "3"]
    }
Then add attributes to explicitly give the structure. Since this is a browser spec we can add attributes. Here's the same form but with some attributes giving the explicit encoding.

    <form enctype='application/json'>
      <input type='text' name='fruit' value='apple' enc='string'>
      <input type='number' name='bottle-on-wall' value='1' enc='array/number'>
      <input type='number' name='bottle-on-wall' value='2' enc='array/number'>
      <input type='number' name='bottle-on-wall' value='3' enc='array/number'>
    </form>

    {
      "fruit": "apple",
      "bottle-on-wall": [1, 2, 3]
    }
Dynamically varying JSON structures by form names and number of form elements is definitely going to be a source of bugs and security problems.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: