This project is archived and is in readonly mode.
ActiveSupport::CoreExtensions::Array::Conversions#to_xml modifies the passed option hash
Reported by ThePhred | June 5th, 2009 @ 09:03 PM | in 3.x
test = {}
[].to_xml( test )
Now test is equal to the following instead of
{}
:
{:indent=>2, :builder=><?xml version="1.0" encoding="UTF-8"?>
<nil-classes type="array"/>
<inspect/>
}
The situation that makes this bad is:
class SomeController < ApplicationController
TO_XML_OPTIONS_HASH = { :indent => 3 }
def some_action
render :xml => SomeModel.all.to_xml( TO_XML_OPTIONS_HASH )
end end
When class caching is on, this causes the TO_XML_OPTIONS_HASH to be modified and the builder in the hash will get appended to every time the action is called.
Comments and changes to this ticket
-
ThePhred June 5th, 2009 @ 09:05 PM
This same issue happened before but was fixed and now has cropped up again. The old ticket is here: http://dev.rubyonrails.org/ticket/8017
-
ThePhred June 5th, 2009 @ 09:09 PM
Also note that in the SomeController example above, if you freeze the hash before you set it to the constant TO_XML_OPTIONS_HASH, you will get a TypeEror: can't modify frozen hash.
-
Rohit Arondekar October 9th, 2010 @ 04:05 AM
- State changed from new to stale
- Importance changed from to
Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>