mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Scrub the invalid paramter value before using it in the error
You should be able to safely use the String error message. So when finding the paramter has an invalid encoding we need to remove the invalid bytes before using it in the error. Otherwise the caller might get another Encoding error if they use the message.
This commit is contained in:
parent
c1f9fa8c69
commit
2513a410f5
2 changed files with 3 additions and 2 deletions
|
@ -32,7 +32,7 @@ module ActionDispatch
|
|||
unless params.valid_encoding?
|
||||
# Raise Rack::Utils::InvalidParameterError for consistency with Rack.
|
||||
# ActionDispatch::Request#GET will re-raise as a BadRequest error.
|
||||
raise Rack::Utils::InvalidParameterError, "Non UTF-8 value: #{params}"
|
||||
raise Rack::Utils::InvalidParameterError, "Invalid encoding for parameter: #{params.scrub}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1024,7 +1024,8 @@ class RequestParameters < BaseRequestTest
|
|||
request.path_parameters = { foo: "\xBE" }
|
||||
end
|
||||
|
||||
assert_equal "Invalid path parameters: Non UTF-8 value: \xBE", err.message
|
||||
assert_predicate err.message, :valid_encoding?
|
||||
assert_equal "Invalid path parameters: Invalid encoding for parameter: <20>", err.message
|
||||
end
|
||||
|
||||
test "parameters not accessible after rack parse error of invalid UTF8 character" do
|
||||
|
|
Loading…
Reference in a new issue