Changeset 9242
- Timestamp:
- 04/08/08 05:05:54 (8 months ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/base.rb (modified) (1 diff)
- trunk/actionpack/lib/action_controller/request.rb (modified) (3 diffs)
- trunk/actionpack/lib/action_view/template_handlers/erb.rb (modified) (1 diff)
- trunk/actionpack/test/controller/request_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r9241 r9242 1 1 *SVN* 2 3 * Automatically parse posted JSON content for Mime::JSON requests. [rick] 4 5 POST /posts 6 {"post": {"title": "Breaking News"}} 7 8 def create 9 @post = Post.create params[:post] 10 # ... 11 end 2 12 3 13 * add json_escape ERB util to escape html entities in json strings that are output in HTML pages. [rick] trunk/actionpack/lib/action_controller/base.rb
r9123 r9242 317 317 # 318 318 # ActionController::Base.param_parsers[Mime::YAML] = :yaml 319 @@param_parsers = { Mime::MULTIPART_FORM => :multipart_form,319 @@param_parsers = { Mime::MULTIPART_FORM => :multipart_form, 320 320 Mime::URL_ENCODED_FORM => :url_encoded_form, 321 Mime::XML => :xml_simple } 321 Mime::XML => :xml_simple, 322 Mime::JSON => :json } 322 323 cattr_accessor :param_parsers 323 324 trunk/actionpack/lib/action_controller/request.rb
r9124 r9242 403 403 when :yaml 404 404 YAML.load(body) 405 when :json 406 if body.blank? 407 {} 408 else 409 data = ActiveSupport::JSON.decode(body) 410 data = {:_json => data} unless data.is_a?(Hash) 411 data.with_indifferent_access 412 end 405 413 else 406 414 {} … … 508 516 end 509 517 510 511 518 MULTIPART_BOUNDARY = %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n 512 519 … … 605 612 raise EOFError, "bad boundary end of body part" unless boundary_end=~/--/ 606 613 607 begin614 begin 608 615 body.rewind if body.respond_to?(:rewind) 609 rescue Errno::ESPIPE616 rescue Errno::ESPIPE 610 617 # Handles exceptions raised by input streams that cannot be rewound 611 618 # such as when using plain CGI under Apache 612 end619 end 613 620 614 621 params trunk/actionpack/lib/action_view/template_handlers/erb.rb
r9241 r9242 4 4 module Util 5 5 HTML_ESCAPE = { '&' => '&', '>' => '>', '<' => '<', '"' => '"' } 6 JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003E', '<' => '\u003C' }6 JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003E', '<' => '\u003C' } 7 7 8 8 # A utility method for escaping HTML tag characters. trunk/actionpack/test/controller/request_test.rb
r9194 r9242 852 852 end 853 853 854 855 854 class XmlParamsParsingTest < Test::Unit::TestCase 855 def test_hash_params 856 person = parse_body("<person><name>David</name></person>")[:person] 857 assert_kind_of Hash, person 858 assert_equal 'David', person['name'] 859 end 860 856 861 def test_single_file 857 862 person = parse_body("<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar></person>") … … 900 905 end 901 906 end 907 908 class JsonParamsParsingTest < Test::Unit::TestCase 909 def test_hash_params 910 person = parse_body({:person => {:name => "David"}}.to_json)[:person] 911 assert_kind_of Hash, person 912 assert_equal 'David', person['name'] 913 end 914 915 private 916 def parse_body(body) 917 env = { 'CONTENT_TYPE' => 'application/json', 918 'CONTENT_LENGTH' => body.size.to_s } 919 cgi = ActionController::Integration::Session::StubCGI.new(env, body) 920 ActionController::CgiRequest.new(cgi).request_parameters 921 end 922 end