rails/rails — Issue #4424: rails 3 crash in json post without contentType
Author: pbrumm
Created: 2012-01-12 16:14:43+00:00
State: open

It has something to do with the depth of the data

in jquery I did a post

$.ajax(
type: "POST"
url: "/offices/bulk"
dataType: "json"
data: JSON.stringify(changes)
success: on_success
error: on_error
)

of

[{"address":{"business":{"addr1":"1510 street Dr","city":"Test","state":"TN","zip":"37215","addr2":""}},"name":"asef1asdf","website_url":"http://asdf.com","email":"emal@addr.com","phones":{"fax":"2383838384","main":"6152693839"},"primary":true,"schedule_restrictions":[{"e_type":"b","name":"Breakfast Hours","day_times":{"1":[{"s_hm":7.3,"e_hm":8.3}],"2":[{"s_hm":7.3,"e_hm":8.3}],"3":[{"s_hm":7.3,"e_hm":8.3}],"4":[{"s_hm":7.3,"e_hm":8.3}],"5":[{"s_hm":7.3,"e_hm":8.3}],"6":[],"0":[]}},{"e_type":"l","name":"Lunch Hours","day_times":{"1":[{"s_hm":11.3,"e_hm":13}],"2":[{"s_hm":11.3,"e_hm":13}],"3":[{"s_hm":11.3,"e_hm":13}],"4":[{"s_hm":11.3,"e_hm":13}],"5":[{"s_hm":11.3,"e_hm":13}],"6":[],"0":[]}},{"e_type":"o","name":"Office Hours","day_times":{"1":[{"s_hm":7.3,"e_hm":16.3}],"2":[{"s_hm":7.3,"e_hm":16.3}],"3":[{"s_hm":7.3,"e_hm":16.3}],"4":[{"s_hm":7.3,"e_hm":16.3}],"5":[{"s_hm":7.3,"e_hm":16.3}],"6":[],"0":[]}},{"e_type":"v","name":"Vendor Hours","day_times":{"1":[{"s_hm":8.3,"e_hm":11.3},{"s_hm":13,"e_hm":16.3}],"2":[{"s_hm":8.3,"e_hm":11.3},{"s_hm":13,"e_hm":16.3}],"3":[{"s_hm":8.3,"e_hm":11.3},{"s_hm":13,"e_hm":16.3}],"4":[{"s_hm":8.3,"e_hm":11.3},{"s_hm":13,"e_hm":16.3}],"5":[{"s_hm":8.3,"e_hm":11.3},{"s_hm":13,"e_hm":16.3}],"6":[],"0":[]}}],"id":"4f049cb319ede8061300000f","loc":[-86.7989489,36.709057]},{"address":{"business":{"addr1":"1401 addr12 dr","city":"Nashville","state":"tn","zip":"37215","addr2":""}},"name":"asef2asdf","website_url":"asdf.com","email":"asef@asdf.com","phones":{"fax":"1342334234","main":"6152608893"},"primary":true,"schedule_restrictions":[{"e_type":"b","name":"Breakfast Hours","day_times":{"1":[{"s_hm":7.3,"e_hm":8.3}],"2":[{"s_hm":7.3,"e_hm":8.3}],"3":[{"s_hm":7.3,"e_hm":8.3}],"4":[{"s_hm":7.3,"e_hm":8.3}],"5":[{"s_hm":7.3,"e_hm":8.3}],"6":[],"0":[]}},{"e_type":"l","name":"Lunch Hours","day_times":{"1":[{"s_hm":11.3,"e_hm":13}],"2":[{"s_hm":11.3,"e_hm":13}],"3":[{"s_hm":11.3,"e_hm":13}],"4":[{"s_hm":11.3,"e_hm":13}],"5":[{"s_hm":11.3,"e_hm":13}],"6":[],"0":[]}},{"e_type":"o","name":"Office Hours","day_times":{"1":[{"s_hm":7.3,"e_hm":16.3}],"2":[{"s_hm":7.3,"e_hm":16.3}],"3":[{"s_hm":7.3,"e_hm":16.3}],"4":[{"s_hm":7.3,"e_hm":16.3}],"5":[{"s_hm":7.3,"e_hm":16.3}],"6":[],"0":[]}},{"e_type":"v","name":"Vendor Hours","day_times":{"1":[{"s_hm":8.3,"e_hm":11.3},{"s_hm":13,"e_hm":16.3}],"2":[{"s_hm":8.3,"e_hm":11.3},{"s_hm":13,"e_hm":16.3}],"3":[{"s_hm":8.3,"e_hm":11.3},{"s_hm":13,"e_hm":16.3}],"4":[{"s_hm":8.3,"e_hm":11.3},{"s_hm":13,"e_hm":16.3}],"5":[{"s_hm":8.3,"e_hm":11.3},{"s_hm":13,"e_hm":16.3}],"6":[],"0":[]}}],"id":"4f049d7219ede80613000011","loc":[-86.7896684,36.1078298]}]

and every time rails would crash with a

Illegal instruction: 4

I then added a

contentType: "application/json"

and the crash goes away.
Simpler json doesn't cause a crash

My guess is that rails is trying to parse post as xml and crashing.

default jquery mime type is

'application/x-www-form-urlencoded'

I am using rails 3.1.3 with a fresh local bundle install on ruby-1.9.2-p290
the route looks like this

match '/offices/bulk' => 'offices#bulk', :via => :post

It crashes before it reaches the bulk method