Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9242 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

[PATCH]Rails Crashes parsing an xml request with "type" as a node

Reported by: isaacfeliu Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveSupport Version: edge
Severity: normal Keywords: xml_simple
Cc: sur

Description

If you have a Type model, with corresponding types_controller, and you're using REST patterns, when you send a POST or PUT request with a valid XML formatted Type resource, Rails will crash with:

You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.update
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/request.rb:13:in `parameters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/request.rb:20:in `method'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1333:in `extract_request_environment'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1282:in `recognize'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:40:in `dispatch'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `synchronize'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process'
...

Supose you have types table like that:

class CreateTypes < ActiveRecord::Migration
  def self.up
    create_table :types do |t|
      t.column :description, :string
      t.column :created_at, :datetime
      t.column :updated_at, :datetime
    end
  end

  def self.down
    drop_table :types
  end
end

the error occurs when you try to POST or PUT a valid Type in xml format, like that:

<?xml version="1.0" encoding="UTF-8"?>
<type>
  <created-at type="datetime">2007-08-01T10:09:32Z</created-at>
  <description>TYPE POR API</description>
  <id type="integer">18</id>
  <updated-at type="datetime">2007-08-06T22:01:46Z</updated-at>
</type>

The error doesn't occur when you're using standard HTTP POST or PUT, only with XML. I think the problem is in xml_simple and "type" as the root node name, if you change it to "ttype", Rails runs as expected.

Sorry, but i'm not expert enought to solve the problem myself!

Isaac.

Attachments

tests_for_failure.diff (1.6 kB) - added by juanjo.bazan on 02/18/08 16:39:04.
A couple of simple tests reproducing the problem
parsing_type_node.diff (3.9 kB) - added by juanjo.bazan on 02/26/08 22:00:42.
Patch solving the issue (include tests), updated to current trunk

Change History

08/25/07 15:34:11 changed by danger

It appears you're using the gems. Try freezing the latest Rails code into your ./vendor/rails directory and see if the error still happens: "rake rails:freeze:edge"

08/27/07 11:46:14 changed by sur

  • cc set to sur.

Please provide a test case for failure.

08/29/07 13:11:35 changed by juanjo.bazan

  • summary changed from Rails Crashes parsing an xml request with "type" as the root node to [PATCH]Rails Crashes parsing an xml request with "type" as a node.

08/29/07 13:12:05 changed by juanjo.bazan

  • version changed from 1.2.3 to edge.

02/18/08 16:39:04 changed by juanjo.bazan

  • attachment tests_for_failure.diff added.

A couple of simple tests reproducing the problem

02/26/08 22:00:42 changed by juanjo.bazan

  • attachment parsing_type_node.diff added.

Patch solving the issue (include tests), updated to current trunk

02/26/08 22:52:02 changed by cavalle

+1

02/27/08 23:11:13 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [8937]) Fix Hash#from_xml with Type records. Closes #9242 [Juanjo Bazan, Isaac Feliu]