diff --git a/actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb b/actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb new file mode 100644 index 0000000000..b494674c91 --- /dev/null +++ b/actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb @@ -0,0 +1,44 @@ +class CGI #:nodoc: + # Add @request.env['RAW_POST_DATA'] for the vegans. + module QueryExtension + # Initialize the data from the query. + # + # Handles multipart forms (in particular, forms that involve file uploads). + # Reads query parameters in the @params field, and cookies into @cookies. + def initialize_query() + if boundary = multipart_form_boundary + @multipart = true + @params = read_multipart(boundary, Integer(env_table['CONTENT_LENGTH'])) + else + @multipart = false + @params = CGI::parse(read_query_params) + end + end + + private + def multipart_form_boundary + multipart_form_boundary_re = %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n # " ruby-mode + + if env_table['REQUEST_METHOD'] == 'POST' + multipart_form_boundary_re.match(env_table['CONTENT_TYPE']).to_a.pop + end + end + + def read_query_params + case env_table['REQUEST_METHOD'] + when 'GET', 'HEAD' + if defined? MOD_RUBY + Apache::request.args or '' + else + env_table['QUERY_STRING'] or '' + end + when 'POST' + stdinput.binmode if stdinput.respond_to?(:binmode) + content = stdinput.read(Integer(env_table['CONTENT_LENGTH'])) or '' + env_table['RAW_POST_DATA'] = content.freeze + else + read_from_cmdline + end + end + end # module QueryExtension +end \ No newline at end of file diff --git a/actionpack/test/controller/raw_post_test.rb b/actionpack/test/controller/raw_post_test.rb new file mode 100644 index 0000000000..98dc7f6ba7 --- /dev/null +++ b/actionpack/test/controller/raw_post_test.rb @@ -0,0 +1,31 @@ +require 'test/unit' +require 'cgi' +require 'stringio' +require File.dirname(__FILE__) + '/../../lib/action_controller/cgi_ext/raw_post_data_fix' + +class RawPostDataTest < Test::Unit::TestCase + def setup + ENV['REQUEST_METHOD'] = 'POST' + ENV['CONTENT_TYPE'] = '' + ENV['CONTENT_LENGTH'] = '0' + end + + def test_raw_post_data + process_raw "action=create_customer&full_name=David%20Heinemeier%20Hansson&customerId=1" + end + + private + def process_raw(query_string) + old_stdin = $stdin + begin + $stdin = StringIO.new(query_string.dup) + ENV['CONTENT_LENGTH'] = $stdin.size.to_s + CGI.new + assert_not_nil ENV['RAW_POST_DATA'] + assert ENV['RAW_POST_DATA'].frozen? + assert_equal query_string, ENV['RAW_POST_DATA'] + ensure + $stdin = old_stdin + end + end +end diff --git a/activerecord/test/column_alias_test.rb b/activerecord/test/column_alias_test.rb new file mode 100644 index 0000000000..06a0a7f3b0 --- /dev/null +++ b/activerecord/test/column_alias_test.rb @@ -0,0 +1,12 @@ +require 'abstract_unit' +require 'fixtures/topic' + +class TestColumnAlias < Test::Unit::TestCase + + def test_column_alias + topic = Topic.find(1) + records = topic.connection.select_all("SELECT id AS pk FROM topics LIMIT 1") + assert_equal(records[0].keys[0], "pk") + end + +end diff --git a/pushgems.rb b/pushgems.rb index a754b56647..c8ccf5d474 100755 --- a/pushgems.rb +++ b/pushgems.rb @@ -2,7 +2,7 @@ build_number = `svn log -q -rhead http://dev.rubyonrails.org/svn/rails`.scan(/r([0-9]*)/).first.first.to_i -%w( actionmailer actionpack activerecord railties ).each do |pkg| +(%w( actionmailer actionpack activerecord railties ) - ARGV).each do |pkg| puts "Pushing: #{pkg} (#{build_number})" `cd #{pkg} && PKG_BUILD=#{build_number} rake pgem && cd ..` end \ No newline at end of file