Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploading XML-file results in Rack::QueryParser::InvalidParameterError #1984

Closed
wuarmin opened this issue Nov 14, 2022 · 2 comments
Closed

Comments

@wuarmin
Copy link

wuarmin commented Nov 14, 2022

Hello,
this works in past rack-versions, but if I try to upload a XML file to a rack 2.2.4 app, I get a
Rack::QueryParser::InvalidParameterError

<!--/tmp/test/test.xml-->
<root>
  <name>100 % Meijer</name>
</root>
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.

Here's a spec which shows the behavior

# frozen_string_literal: true

require "hanami/middleware/body_parser"
require "hanami/router"
require "rack/builder"
require "rack/test"
require "json"

RSpec.describe "post xml behavior" do
  include Rack::Test::Methods
  let(:app) do
    r = router
    Rack::Builder.new do
      # use Hanami::Middleware::BodyParser, :json
      run r
    end
  end

  let(:router) do
    Hanami::Router.new do
      post "/upload-xml", to: ->(_env) { [200, {}, ["resources/:id"]] }
    end
  end

  it "responds to /upload-xml" do
    post "/upload-xml", "<root><name>100% Meijer</name></root>", "CONTENT_TYPE" => "multipart/form-data"
    expect(last_response.status).to eq(200)
  end
end

The same happens to a JSON-post. Please checkout this issue: hanami/router#237

Thanks

@wuarmin wuarmin changed the title When I upload a XML file, I get Rack::QueryParser::InvalidParameterError Uploading XML-file results in Rack::QueryParser::InvalidParameterError Nov 14, 2022
@jeremyevans
Copy link
Contributor

As pointed out in hanami/router#237 (comment), this is a Hanami bug.

@wuarmin
Copy link
Author

wuarmin commented Nov 14, 2022

@jeremyevans thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants