Permalink
Browse files

Clarify route encoding test

Since this test changed in 9220935 I noticed that it really doesn't make
sense anymore. I split the tests into 2 groups to explain what each one
does.

First these routes should throw a `bad_request` when the encoding isn't
valid. We're expecting UTF8 encoding and passing binary, that should be
a bad request.

For the second test we are setting the `show` route to set
`self.binary_params_for?` for that route which will convert the
parameters and return a `:ok` instead of a `:bad_request`.
  • Loading branch information...
eileencodes committed Aug 1, 2017
1 parent 9668cc3 commit b5ef7d2f72e7c4ef1ebb9a85653aca42742b33b2
Showing with 12 additions and 6 deletions.
  1. +12 −6 actionpack/test/dispatch/routing_test.rb
@@ -4423,17 +4423,15 @@ def show
end
end
test "invalid UTF-8 encoding returns a 400 Bad Request" do
test "invalid UTF-8 encoding returns a bad request" do
with_routing do |set|
set.draw do
get "/bar/:id", to: redirect("/foo/show/%{id}")
get "/foo/show(/:id)", to: "test_invalid_urls/foo#show"
ok = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] }
get "/foobar/:id", to: ok
ActiveSupport::Deprecation.silence do
get "/foo(/:action(/:id))", controller: "test_invalid_urls/foo"
get "/:controller(/:action(/:id))"
end
end
@@ -4444,16 +4442,24 @@ def show
get "/foo/%E2%EF%BF%BD%A6"
assert_response :bad_request
get "/foo/show/%E2%EF%BF%BD%A6"
assert_response :bad_request
get "/bar/%E2%EF%BF%BD%A6"
assert_response :bad_request
get "/foobar/%E2%EF%BF%BD%A6"
assert_response :bad_request
end
end
test "params encoded with binary_params_for? are treated as ASCII 8bit" do
with_routing do |set|
set.draw do
get "/foo/show(/:id)", to: "test_invalid_urls/foo#show"
end
get "/foo/show/%E2%EF%BF%BD%A6"
assert_response :ok
end
end
end
class TestOptionalRootSegments < ActionDispatch::IntegrationTest

0 comments on commit b5ef7d2

Please sign in to comment.