Description
Sinatra 2.0.0
When post request has a json body with non utf-8 encoding characters in keys, Sinatra middleware returns 400 with the following body:
Invalid query parameters: invalid byte sequence in UTF-8
Request body example:
{ "\xf0\x90\x28\xbc": 3 }
Our Sinatra app has been configured to enable raise_errors and disable show_exceptions
enable :raise_errors
disable :show_exceptions
We would like to customize error message, so we registered a BadRequest error handler:
error Sinatra::BadRequest do
[400, {}, ['some error message']]
end
This error handling causes Sinatra app to raise exception internally. After a bit of debugging, crash happens @
Line 1030 in 5de6498
I guess "@params" is nil because due to encoding issue "@params" was not properly initialized @
Line 1089 in 5de6498
Calling "params" method of request object raises exception which is handled but "@params" is left uninitialized.