Permalink
Browse files

Fix path encoding tests if Ruby version is 1.9.3

In Ruby 1.9.3 `#b` is not defined. The change I made to Rack (see
rack/rack@b62cd8a) and Rails (see #29062) won't work for Ruby
1.9.3 because of this.

For less than Ruby 2.0 we should skip the
`test_normalize_path_maintains_string_encoding` test because it won't
pass. `#b` will always be undefined for the Rack dependent change, and
since the Rack change isn't present then Rails will see a bad request
instead of a not found for the routing test.

For the routing test we should handle it differently if it's Ruby 1.9.3
(because then the behavior is clear). Ruby 1.9.3 will always return a
bad request because we can't fix the problem in Rack. The routing test
asserts the requests return a bad request in Ruby 1.9.3 or return the
appropriate response in Ruby 2.0.0 and above.
  • Loading branch information...
eileencodes committed Jun 12, 2017
1 parent a2b2161 commit 31dfc4f99211b9e3a8675b2983389f57b037e5f8
Showing with 41 additions and 15 deletions.
  1. +40 −15 actionpack/test/dispatch/routing_test.rb
  2. +1 −0 actionpack/test/journey/router/utils_test.rb
@@ -4196,26 +4196,51 @@ def show
end
end
test "invalid UTF-8 encoding is treated as ASCII 8BIT encode" 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"
get "/foo(/:action(/:id))", :controller => "test_invalid_urls/foo"
get "/:controller(/:action(/:id))"
if RUBY_VERSION < '2.0.0'
test "invalid UTF-8 encoding returns a 400 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"
get "/foo(/:action(/:id))", :controller => "test_invalid_urls/foo"
get "/:controller(/:action(/:id))"
end
get "/%E2%EF%BF%BD%A6"
assert_response :bad_request
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
end
end
else
test "invalid UTF-8 encoding is treated as ASCII 8BIT encode" 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"
get "/foo(/:action(/:id))", :controller => "test_invalid_urls/foo"
get "/:controller(/:action(/:id))"
end
get "/%E2%EF%BF%BD%A6"
assert_response :not_found
get "/%E2%EF%BF%BD%A6"
assert_response :not_found
get "/foo/%E2%EF%BF%BD%A6"
assert_response :not_found
get "/foo/%E2%EF%BF%BD%A6"
assert_response :not_found
get "/foo/show/%E2%EF%BF%BD%A6"
assert_response :ok
get "/foo/show/%E2%EF%BF%BD%A6"
assert_response :ok
get "/bar/%E2%EF%BF%BD%A6"
assert_response :redirect
get "/bar/%E2%EF%BF%BD%A6"
assert_response :redirect
end
end
end
end
@@ -34,6 +34,7 @@ def test_normalize_path_uppercase
end
def test_normalize_path_maintains_string_encoding
skip "#b is not defined" if RUBY_VERSION < '2.0.0'
path = "/foo%AAbar%AAbaz".b
assert_equal Encoding::ASCII_8BIT, Utils.normalize_path(path).encoding
end

0 comments on commit 31dfc4f

Please sign in to comment.