Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveSupport::CoreExtensions::Array::Conversions#to_xml modifies the passed option hash

#2769
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 =&gt; 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.

Reported by ThePhred · June 5th, 2009 @ 09:03 PM

State: stale
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. ThePhred
    ThePhred

    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

    June 5th, 2009 @ 09:05 PM

  2. ThePhred
    ThePhred

    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.

    June 5th, 2009 @ 09:09 PM

  3. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  4. Rohit Arondekar
    Rohit Arondekar
    • 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.

    October 9th, 2010 @ 04:05 AM