Sha256: b93a4432965759ce228edbd58f7e049492b27bf12134a6d8cbe93d722d5d6b77

Contents?: true

Size: 1.48 KB

Versions: 48

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

require "abstract_unit"

class ParameterEncodingController < ActionController::Base
  skip_parameter_encoding :test_bar
  skip_parameter_encoding :test_all_values_encoding

  def test_foo
    render body: params[:foo].encoding
  end

  def test_bar
    render body: params[:bar].encoding
  end

  def test_all_values_encoding
    render body: ::JSON.dump(params.values.map(&:encoding).map(&:name))
  end
end

class ParameterEncodingTest < ActionController::TestCase
  tests ParameterEncodingController

  test "properly transcodes UTF8 parameters into declared encodings" do
    post :test_foo, params: { "foo" => "foo", "bar" => "bar", "baz" => "baz" }

    assert_response :success
    assert_equal "UTF-8", @response.body
  end

  test "properly encodes ASCII_8BIT parameters into binary" do
    post :test_bar, params: { "foo" => "foo", "bar" => "bar", "baz" => "baz" }

    assert_response :success
    assert_equal "ASCII-8BIT", @response.body
  end

  test "properly encodes all ASCII_8BIT parameters into binary" do
    post :test_all_values_encoding, params: { "foo" => "foo", "bar" => "bar", "baz" => "baz" }

    assert_response :success
    assert_equal ["ASCII-8BIT"], JSON.parse(@response.body).uniq
  end

  test "does not raise an error when passed a param declared as ASCII-8BIT that contains invalid bytes" do
    get :test_bar, params: { "bar" => URI.parser.escape("bar\xE2baz".b) }

    assert_response :success
    assert_equal "ASCII-8BIT", @response.body
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
jets-1.9.7 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.9.6 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.9.5 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.9.4 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.9.3 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.9.2 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.9.1 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.9.0 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.8.14 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.8.13 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.8.12 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.8.11 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.8.10 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.8.9 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.8.8 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.8.7 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.8.6 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.8.5 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.8.4 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb
jets-1.8.3 vendor/rails/actionpack/test/controller/parameter_encoding_test.rb