sinatra-param icon indicating copy to clipboard operation
sinatra-param copied to clipboard

ArgumentError - invalid byte sequence in UTF-8

Open tecnobrat opened this issue 6 years ago • 1 comments

app_1      | 2019-03-29 15:55:38 - ArgumentError - invalid byte sequence in UTF-8:
app_1      |    /usr/local/bundle/gems/sinatra-param-1.6.0/lib/sinatra/param.rb:122:in `==='
app_1      |    /usr/local/bundle/gems/sinatra-param-1.6.0/lib/sinatra/param.rb:122:in `block in validate!'
app_1      |    /usr/local/bundle/gems/sinatra-param-1.6.0/lib/sinatra/param.rb:115:in `each'
app_1      |    /usr/local/bundle/gems/sinatra-param-1.6.0/lib/sinatra/param.rb:115:in `validate!'
app_1      |    /usr/local/bundle/gems/sinatra-param-1.6.0/lib/sinatra/param.rb:23:in `param'
app_1      |    /service/lib/routes/avatar.rb:19:in `block in <class:Application>'

The line in my code is: param :email, String, blank: false

The request made to the server has a param of: ?email=%28t%B3odei%[email protected]

tecnobrat avatar Mar 29 '19 16:03 tecnobrat

%B3 by itself is an invalid UTF-8 byte sequence. You can verify this by entering the string into an HTML / percent-encoding decoder; the result is invalid (�).

It looks like the the rescue clause where we try to encode the invalid value to generate the exception is itself raising ArgumentError. I'll look into how we might do this more safely to handle invalid string values.

mattt avatar Jul 26 '19 14:07 mattt