macek/jquery-serialize-object

Chrome crashes when using serializeJSON

awsp opened this issue · 2 comments

awsp commented

Not sure if this is a real bug, but it annoys me since it crashes my Chrome every time I do it.
JSFiddle: http://jsfiddle.net/1skp3rg7/3/

I have 3 buttons, each one triggers the following corresponded function.
I have an array named aa[20141225][date].
In the JSFiddle example, serializeObject and serializeArray work just fine, but serializeJSON crashes my browser (using chrome). When you test it please be aware that clicking serializeJSON will crash your browser, I need to refresh my page when it crashes. :D

serializeJSON()
serializeObject()
serializeArray()

I suspect it treats my nested array 20141225 that it is actually an index of an array and therefore it is allocating that many elements in an array until it ran out allocated memories and eventually crashed.
How would I make 20141225 parsed as a string key?

You're exactly right. See: #18 crash maybe due to incorrect array length

This has been a low-priority "fix" for me because of three reasons.

  1. technically, it's not broken.
  2. the w3c spec for json form submissions operates the same way
  3. the workaround for your case is relatively easy
<input name="aa[0][id]" value="20141225">
<input name="aa[0][date]" value="2014/12/23">

Now both 20141225 and 2014/12/23 will be serialized as strings. The resulting object will look like:

{
  aa: [{
    id: "20141225",
    value: "2014/12/23"
  }]
}

If there's anything else I can help you with, let me know.

awsp commented

Thanks for your reply.
Since it is actually a key in my Mongo Collection to allow random access, I actually "resolve" it by putting a string before 20141225 to something like D20141225 in order cast it to a string.
But thanks for the workaround, maybe I should try your way instead.
Happy new year!