When I upload a XML file, I get Rack::QueryParser::InvalidParameterError

this works in Hanami 1.3, but if I try to upload a XML file to a hanami 2 app, I get a

  <name>100 % Meijer</name>
curl -F 'file=@/tmp/test/test.xml' http://localhost:2300/test/upload

I get following error

Rack::QueryParser::InvalidParameterError: invalid %-encoding

The Content-Type is multipart/form-data. Changing it to application/xml does not change anything.
Is there a way to configure the Hanami 2 application to make this work?


@wuarmin This seems to be a Rack bug: Exception when JSON body contains % · Issue #237 · hanami/router · GitHub

@jodosha Thanks.
Oh, is there already an open issue at rack? I can’t find any? Do you know a workaround?

I opened an issue Uploading XML-file results in Rack::QueryParser::InvalidParameterError · Issue #1984 · rack/rack · GitHub

@jodosha It seems it’s a hanami issue. It seems that the issue lies here: router/router.rb at d4f7a677a34978f24c153b9c96b90a03dd3e3a9b · hanami/router · GitHub

We have to change the multipart parsing.

       invalid %-encoding (<root><name>100% Meijer</name></root>)
     # /usr/local/bundle/gems/rack-2.2.4/lib/rack/utils.rb:57:in `unescape'
     # /usr/local/bundle/gems/rack-2.2.4/lib/rack/query_parser.rb:159:in `unescape'
     # /usr/local/bundle/gems/rack-2.2.4/lib/rack/query_parser.rb:73:in `block (2 levels) in parse_nested_query'
     # /usr/local/bundle/gems/rack-2.2.4/lib/rack/query_parser.rb:73:in `map!'
     # /usr/local/bundle/gems/rack-2.2.4/lib/rack/query_parser.rb:73:in `block in parse_nested_query'
     # /usr/local/bundle/gems/rack-2.2.4/lib/rack/query_parser.rb:72:in `each'
     # /usr/local/bundle/gems/rack-2.2.4/lib/rack/query_parser.rb:72:in `parse_nested_query'
     # /usr/local/bundle/gems/rack-2.2.4/lib/rack/utils.rb:102:in `parse_nested_query'
     # /usr/local/bundle/gems/hanami-router-2.0.0.rc1/lib/hanami/router.rb:923:in `_params'

@wuarmin I’ll have a look at it. Thanks.

@jodosha I had to fix this for myself quickly. Here’s my approach: Fix parsing of multipart/form-data by wuarmin · Pull Request #239 · hanami/router · GitHub