This project is archived and is in readonly mode.

#69 ✓stale
Matthew Moore

UrlEncodedPairParser creates wrong params hash with nested attributes in arrays

Reported by Matthew Moore | April 30th, 2008 @ 07:25 PM

In edge rails, sending in request attributes with the following:

&email[to_new_contacts][][contact_attributes][first_name]=first

&email[to_new_contacts][][contact_attributes][middle_name]=middle

&email[to_new_contacts][relationship]=friend

&email[to_new_contacts][][contact_attributes][first_name]=first2

&email[to_new_contacts][][contact_attributes][middle_name]=middle2

&email[to_new_contacts][relationship]=friend2

Creates a very unexpected params value. The attached test compares what the desired output is, versus what is actually output by UrlEncodedPairParser.

Shouldn't the params hash look similar to the following? It looks much different, as you'll see in the test.

:email => :to_new_contacts => [

{:relationship => '..', : contact_attributes => { :first_name => '..' } },

{:relationship => '..', : contact_attributes => { :first_name => '..' } }

]

Comments and changes to this ticket

  • Carl Porth

    Carl Porth May 28th, 2008 @ 03:56 AM

    In the following arguments, you are treating email[to_new_contacts] like an array with []

    &email[to_new_contacts][][contact_attributes][first_name]=first

    &email[to_new_contacts][][contact_attributes][middle_name]=middle

    &email[to_new_contacts][][contact_attributes][first_name]=first2

    &email[to_new_contacts][][contact_attributes][middle_name]=middle2

    However, in these arguments, you are treating email[to_new_contacts] like a hash by indexing it with "relationship"

    &email[to_new_contacts][relationship]=friend

    &email[to_new_contacts][relationship]=friend2

    You probably just want to use a hash like this:

    &email[to_new_contacts][friend][contact_attributes][first_name]=first

    &email[to_new_contacts][friend][contact_attributes][middle_name]=middle

    &email[to_new_contacts][friend2][contact_attributes][first_name]=first2

    &email[to_new_contacts][friend2][contact_attributes][middle_name]=middle2

    &email[to_new_contacts][relationship]=friend

    &email[to_new_contacts][relationship]=friend2

    Which will create these params:

    {"email"=>
      {"to_new_contacts"=>
        {"friend2"=>
          {"contact_attributes"=>
            {"first_name"=>"first2", "middle_name"=>"middle2"}},
         "relationship"=>"friend",
         "friend"=>
          {"contact_attributes"=>
            {"first_name"=>"first", "middle_name"=>"middle"}}}}}
    
  • Stephen Heuer

    Stephen Heuer July 12th, 2008 @ 09:57 PM

    • Tag set to actionpack, bug, closed, request, urlencodedpairparser

    We are having the same problem. Except it seems to only be a problem when we are submitting via Ajax and using Form#serialize

    When submitted via Form#serialize looking in firebug, it shows that the this is how the attributes are being sent:

    user[phone_numbers_attributes][][extension]
    user[phone_numbers_attributes][][extension]
    user[phone_numbers_attributes][][phone_number] = 1234567899
    user[phone_numbers_attributes][][phone_number] = 1234567890
    user[phone_numbers_attributes][][phone_type] = cell
    user[phone_numbers_attributes][][phone_type] = Home
    user[phone_numbers_attributes][][primary]
    user[phone_numbers_attributes][][primary]
    

    This is what it looks like in the params object:

    {"user"=>
      {"phone_numbers_attributes"=>
        [
          {"primary"=>""}, 
          {"primary"=>"", "phone_number"=>"1234567890"}, 
          {"extension"=>"", "phone_number"=>"1234567899"}, 
          {"phone_type"=>"Home", "extension"=>""}, 
          {"phone_type"=>"Cell"}
        ]
      }
    }
    

    When submitted via normal form posting we get this in the params object:

    {"user"=>
      {"phone_numbers_attributes"=>
        [
          {"phone_type"=>"Home", "primary"=>"", "extension"=>"", "phone_number"=>"1234567899"}, 
          {"phone_type"=>"Cell", "primary"=>"", "extension"=>"", "phone_number"=>"1234567890"}
        ]
      }
    }
    

    Also, Why does submitting via the Ajax and Form#serialize do empty fields show up as a blank string, but normal form submitting does not?

  • Stephen Heuer

    Stephen Heuer July 12th, 2008 @ 10:03 PM

    • Tag changed from actionpack, bug, closed, request, urlencodedpairparser to actionpack, bug, request, urlencodedpairparser

    Here is a link to the problem in the old rails trac:

    http://dev.rubyonrails.org/ticket/8775

  • Comron Sattari

    Comron Sattari September 17th, 2008 @ 09:40 PM

    • Tag changed from actionpack, bug, request, urlencodedpairparser to actionpack, bug, request, urlencodedpairparser

    This old ticket is related as well, http://dev.rubyonrails.org/ticke.... I'm still having this problem, I was hoping it would have been fixed in 2.1.

    Comron

  • Ivan Vanderbyl

    Ivan Vanderbyl September 18th, 2008 @ 12:11 AM

    A patch which (mostly) fixes this problem is available here http://www.vector-seven.com/2008...

    I'm using it in production with minor tweaks to the form helpers and I have had very few issues.

    Also an idea to compact! the arrays which are returned as they often contain nils.

  • Pratik

    Pratik December 19th, 2008 @ 03:58 PM

    • State changed from “new” to “incomplete”

    We need a patch or even a failing test case. Will reopen after that.

    Thanks.

  • CancelProfileIsBroken

    CancelProfileIsBroken August 4th, 2009 @ 05:15 PM

    • Tag changed from actionpack, bug, request, urlencodedpairparser to actionpack, bug, bugmash, request, urlencodedpairparser
  • Rizwan Reza

    Rizwan Reza January 20th, 2010 @ 10:52 AM

    • State changed from “incomplete” to “stale”
    • Tag changed from actionpack, bug, bugmash, request, urlencodedpairparser to actionpack, bug, request, urlencodedpairparser
  • Thomas Pedersen

    Thomas Pedersen October 13th, 2010 @ 04:21 AM

    • Importance changed from “” to “”

    It would be nice to get this fixed. It has been three years now...

  • Santiago Pastorino

    Santiago Pastorino October 13th, 2010 @ 02:11 PM

    • State changed from “stale” to “open”

    Thomas can you provide a patch with a test case or at least a test case only?.
    Thanks.

  • Thomas Pedersen

    Thomas Pedersen October 13th, 2010 @ 05:19 PM

    I have attached a view template that demonstrates the problem. You have to set up a simple controller and an action in routes.rb for it work, but that takes two minutes.

    The form conctains the following fields:







    When you submit the form normally, Rails groups the values proper in params[] like this:

    Parameters: {"commit"=>"Subtmit", "rule"=>{"condition_list"=>[{"text"=>"text1", "value"=>"value1"}, {"text"=>"text2", "value"=>"value2"}, {"text"=>"text3", "value"=>"value3"}]}}

    But when you use button_to_remove to submit via Ajax, the values are no longer properly grouped:

    Parameters: {"commit"=>"Submit", "authenticity_token"=>"ZW+GHWqfHCpp4rDp67xYHn2a7iOJlbgLg1YYYVZJb9o=", "id"=>"1", "rule"=>{"condition_list"=>[{"text"=>"text1"}, {"text"=>"text2"}, {"text"=>"text3", "value"=>"value1"}, {"value"=>"value2"}, {"value"=>"value3"}]}}

  • Ryan Bigg

    Ryan Bigg October 19th, 2010 @ 08:27 AM

    • Tag cleared.

    Automatic cleanup of spam.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:48 PM

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:48 PM

    • State changed from “open” to “stale”

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>

Pages