diff options
Diffstat (limited to 'actionpack')
-rwxr-xr-x | actionpack/lib/action_controller/base.rb | 11 | ||||
-rwxr-xr-x | actionpack/lib/action_controller/cgi_ext/cgi_methods.rb | 14 | ||||
-rw-r--r-- | actionpack/test/controller/webservice_test.rb | 22 |
3 files changed, 36 insertions, 11 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index ab8cc1802c..e4877f82fd 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -278,16 +278,11 @@ module ActionController #:nodoc: # behavior you can re-register XmlSimple as application/xml handler and enable application/x-yaml like # this: # - # ActionController::Base.param_parsers['application/xml'] = Proc.new do |data| - # XmlSimple.xml_in(data, 'ForceArray' => false) - # end - # - # ActionController::Base.param_parsers['application/x-yaml'] = Proc.new do |data| - # |post| YAML.load(post) - # end + # ActionController::Base.param_parsers['application/xml'] = :xml_simple + # ActionController::Base.param_parsers['application/x-yaml'] = :yaml # @@param_parsers = { - 'application/xml' => Proc.new { |post| node = XmlNode.from_xml(post); { node.node_name => node } }, + 'application/xml' => :xml_node } cattr_accessor :param_parsers diff --git a/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb b/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb index 89f982f56f..feab806077 100755 --- a/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb +++ b/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb @@ -59,7 +59,19 @@ class CGIMethods #:nodoc: end def self.parse_formatted_request_parameters(format, raw_post_data) - ActionController::Base.param_parsers[format].call(raw_post_data) || {} + params = case strategy = ActionController::Base.param_parsers[format] + when Proc + strategy.call(raw_post_data) + when :xml_node + node = XmlNode.from_xml(raw_post_data) + { node.node_name => node } + when :xml_simple + XmlSimple.xml_in(raw_post_data, 'ForceArray' => false) + when :yaml + YAML.load(raw_post_data) + end + + params || {} rescue Object => e { "exception" => "#{e.message} (#{e.class})", "backtrace" => e.backtrace, "raw_post_data" => raw_post_data, "format" => format } diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb index 844ac723ba..6275cfb6d0 100644 --- a/actionpack/test/controller/webservice_test.rb +++ b/actionpack/test/controller/webservice_test.rb @@ -27,6 +27,8 @@ class WebServiceTest < Test::Unit::TestCase def setup @controller = TestController.new + ActionController::Base.param_parsers.clear + ActionController::Base.param_parsers['application/xml'] = :xml_node end def test_check_parameters @@ -55,12 +57,28 @@ class WebServiceTest < Test::Unit::TestCase def test_register_and_use_yaml ActionController::Base.param_parsers['application/x-yaml'] = Proc.new { |d| YAML.load(d) } process('POST', 'application/x-yaml', {"entry" => "loaded from yaml"}.to_yaml) + assert_equal 'entry', @controller.response.body assert @controller.params.has_key?(:entry) assert_equal 'loaded from yaml', @controller.params["entry"] - ensure - ActionController::Base.param_parsers['application/x-yaml'] = nil end + def test_register_and_use_yaml_as_symbol + ActionController::Base.param_parsers['application/x-yaml'] = :yaml + process('POST', 'application/x-yaml', {"entry" => "loaded from yaml"}.to_yaml) + assert_equal 'entry', @controller.response.body + assert @controller.params.has_key?(:entry) + assert_equal 'loaded from yaml', @controller.params["entry"] + end + + def test_register_and_use_xml_simple + ActionController::Base.param_parsers['application/xml'] = :xml_simple + process('POST', 'application/xml', '<request><summary>content...</summary><title>SimpleXml</title></request>' ) + assert_equal 'summary, title', @controller.response.body + assert @controller.params.has_key?(:summary) + assert @controller.params.has_key?(:title) + assert_equal 'content...', @controller.params["summary"] + assert_equal 'SimpleXml', @controller.params["title"] + end def test_deprecated_request_methods process('POST', 'application/x-yaml') |