XML param parsing is slightly rude in that it collapses "degenerate" cases to non-array values. Empty arrays collapse to nil, and an array with one value collapses to just that value. On top of that, you have to traverse an intermediate hash to get to the array values. This patch to ActiveSupport corrects XML array parsing to always generate an array: either an array that's empty, has one value, or has many values. It also removes the intermediate hash.
Before:
Hash.from_xml '<images></images>'
# => {:images => nil}
Hash.from_xml '<images><image>foo.jpg</image></images>'
# => {:images => {:image => "foo.jpg"}}
Hash.from_xml '<images><image>foo.jpg</image><image>bar.jpg</image></images>'
# => {:images => {:image => ["foo.jpg", "bar.jpg"]}}
After:
Hash.from_xml '<images type="array"></images>'
# => {:images => []}
Hash.from_xml '<images type="array"><image>foo.jpg</image></images>'
# => {:images => ["foo.jpg"]}
Hash.from_xml '<images type="array"><image>foo.jpg</image><image>bar.jpg</image></images>'
# => {:images => ["foo.jpg", "bar.jpg"]}
Note that XML is whitespace sensitive, so putting whitespace (like a line break) into an otherwise empty array royally messes things up. So don't do that.