sferik/rails_admin — Issue #835: Hash Serialized columns crash edit
Author: elado
Created: 2011-11-16 05:33:26+00:00
State: open

For arrays it's working great (and the test @ https://github.com/mattsears/rails_admin/commit/d12e09b040ef42115bc7638ec6a1abf33dd5dee8 tests arrays)

But for hashes,

{"x"=>"y"}

I get an error:

syntax error on line 0, col 9: `'

Stack trace:

ruby-1.9.3-p0/lib/ruby/1.9.1/syck.rb:135:in `load'
ruby-1.9.3-p0/lib/ruby/1.9.1/syck.rb:135:in `load'
ruby-1.9.3-p0@setapp_r311/bundler/gems/rails_admin-5483935fd170/app/controllers/rails_admin/main_controller.rb:304:in `block in get_attributes'
ruby-1.9.3-p0@setapp_r311/bundler/gems/rails_admin-5483935fd170/app/controllers/rails_admin/main_controller.rb:301:in `each'
ruby-1.9.3-p0@setapp_r311/bundler/gems/rails_admin-5483935fd170/app/controllers/rails_admin/main_controller.rb:301:in `get_attributes'
activesupport (3.1.1) lib/active_support/callbacks.rb:457:in `_run__4098748544951268412__process_action__4416858203427358007__callbacks'

I see the argument in the request parameters and it looks fine:

"data"=>"{\"x\"=>\"y\"}",

The reason is that the code uses `YAML::load` to load the string, but the input is not YAML (for arrays, by chance it is).

YAML::load('["x", "y"]') # fine
YAML::load('{"x"=>"y"}') # error
YAML::load('{x: "y"}') # no error

It should put YAML and not inspect in the input from the first place, and probably handle parsing errors.