Skip to content

Pull request #136 breaks JSON encoded parameters with Server 500 error #139

@jonhyman

Description

@jonhyman

The latest commit to bring in pull request #136 broke JSON encoded parameters for me.

I couldn't get a good spec working on this, yet when I mounted with Rack and ran a server, I could reproduce. Here's how to reproduce:

  1. Create config.ru
require 'multi_json'
require 'grape'

class Foo < Grape::API
  post do
    params[:cities].map do |c|
      c[:city][:name]
    end.join(' ')
  end
end

run Rack::URLMap.new "/" => Foo
  1. Run the server with rackup -p 3000
  2. Open up irb and type
require 'multi_json'
require 'rest-client'
city1 = {:city => {:name => "Dallas"}}
city2 = {:city => {:name => "Austin"}}
parameters = MultiJson.encode({:cities => [city1, city2]})
RestClient.post('http://localhost:3000', parameters)

On master, this will throw a Server 500 error.

If you change lib/grape/middleware/formatter.rb line 18 from

env.dup.inject({}){|h,(k,v)| h[k.downcase[5..-1]] = v if k.downcase.start_with?('http_'); h}

back to

env.dup.inject({}){|h,(k,v)| h[k.downcase] = v; h}

then rerunning will produce the proper output of "Dallas Austin"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions