From b388ca41d8b26f027a43e96c5ad0950a6bf2f5d7 Mon Sep 17 00:00:00 2001 From: Artem Rashev Date: Mon, 19 Sep 2016 21:54:23 +0300 Subject: Fixed CONTENT_LENGTH header in ActionController::TestRequest CONENT_LENGTH setted by string length, which is equal to number of characters in string but StringIO.length is byte sequence and when payload contains non-ASCII characters, stream's length will be different. That's why real byte length should be used for CONTENT_LENGTH header. Add unit test for CONTENT_LENGTH header fix It just passes non-ascii symbols as parameters and verifies that "CONTENT_LENGTH" header has content bytes count as value. --- actionpack/test/controller/request/test_request_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/request/test_request_test.rb b/actionpack/test/controller/request/test_request_test.rb index fa049fbc9f..da6fa1388b 100644 --- a/actionpack/test/controller/request/test_request_test.rb +++ b/actionpack/test/controller/request/test_request_test.rb @@ -11,6 +11,16 @@ class ActionController::TestRequestTest < ActionController::TestCase assert_equal nil, ActionController::TestSession::DEFAULT_OPTIONS[:myparam] end + def test_content_length_has_bytes_count_value + non_ascii_parameters = { data: { content: "Latin + Кириллица" } } + @request.set_header "REQUEST_METHOD", "POST" + @request.set_header "CONTENT_TYPE", "application/json" + @request.assign_parameters(@routes, "test", "create", non_ascii_parameters, + "/test", [:data, :controller, :action]) + assert_equal(@request.get_header("CONTENT_LENGTH"), + StringIO.new(non_ascii_parameters.to_json).length.to_s) + end + ActionDispatch::Session::AbstractStore::DEFAULT_OPTIONS.each_key do |option| test "rack default session options #{option} exists in session options and is default" do assert_equal(ActionDispatch::Session::AbstractStore::DEFAULT_OPTIONS[option], -- cgit v1.2.3