This project is archived and is in readonly mode.
Sending emtpy params to a xml resource throws exception
-
David Trasbo
- Assigned user set to José Valim
I've done some research and this is what I've come up with.
The root cause of this is really that the request body that Active Resource makes when you call
createwith no arguments looks like this:<?xml version="1.0" encoding="UTF-8"?> <product> </product>When it reaches Rails, it'll use
Hash.from_xmlso it can convert that XML into something that fits in theparamshash.Hash.from_xmlwill return this:{"product"=>"\n"}Technically, that's correct because what's in between those tags is really a newline. The result is that
params[:product]returns"\n", which makes Active Record vomit here because strings don't respond tostringify_keys:def attributes=(new_attributes, guard_protected_attributes = true) return if new_attributes.nil? attributes = new_attributes.stringify_keys # ... endI've attached a patch that fixes this. I believe it's the appropriate place fix it: The XML generated by Active Resource is correct and the return value of
Hash.from_xmlis also really correct. The fix will makeActiveRecord::Base#attributes=let nothing but hashes pass through. -
Repository
- State changed from new to committed
(from [786342e17f42799ef889cf6127fe97e9598272e0]) Return from ActiveRecord::Base#attributes= unless value is a hash [#4070 Sending emtpy params to a xml resource throws exception state:committed]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/786342e17f42799ef889cf6127fe97...
