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

Use symbol of mime type instead of object to get correct parser #23792

Closed
wants to merge 1 commit into from

Conversation

meinac
Copy link
Contributor

@meinac meinac commented Feb 20, 2016

After registering new :json mime type parsers.fetch can't find the mime type because new mime type is not equal to old one. Using symbol of the mime type as key on parsers hash solves the problem.

Closes #23766.

@rails-bot
Copy link

r? @kaspth

(@rails-bot has picked a reviewer for you, use r? to override)

After registering new `:json` mime type `parsers.fetch` can't find the mime type because new mime type is not equal to old one. Using symbol of the mime type as key on parsers hash solves the problem.

Closes rails#23766
@meinac
Copy link
Contributor Author

meinac commented Feb 20, 2016

I've fixed the failing tests but registering new parser api has been changed with this way. If you think it's not a good change I can only filter param_parsers in parse_formatted_parameters method to get correct one with it's symbol like

parsers.select{ |mt, p| mt.symbol == content_mime_type.symbol }

@rafaelfranca WDYT?

@rthbound
Copy link
Contributor

Confirmed by modifying process from the associated issue to use @meinac's branch:

mkdir recreate_bug
echo "2.3.0" >> recreate_bug/.ruby-version
cd recreate_bug
echo "source 'https://rubygems.org'" >> Gemfile
echo "gem 'rails', git: 'git@github.com:meinac/rails.git', branch: 'action_pack_json_parser_bug'"  >> Gemfile
gem install bundler --no-ri --no-rdoc
bundle
rails new --api --force .
sed -i "s/gem 'rails.*$/gem 'rails', git: 'git@github.com:meinac\/rails.git', branch: 'action_pack_json_parser_bug'" Gemfile
bundle
spring stop
rails g scaffold Bug
rake db:migrate
echo "Mime::Type.unregister :json" >> config/initializers/mime_types.rb
echo "Mime::Type.register 'application/json', :json, %w( text/x-json application/jsonrequest application/vnd.api+json )" >> config/initializers/mime_types.rb
rails s

And

curl -XPOST -H 'Content-Type: application/vnd.api+json' http://localhost:3000/bugs -d '{"maybe_a_bug": true}'

With these changes, params are again processed correctly.

@dhh dhh assigned rafaelfranca and unassigned kaspth Feb 22, 2016
rafaelfranca added a commit that referenced this pull request Feb 22, 2016
Use symbol of mime type instead of object to get correct parser
@rafaelfranca
Copy link
Member

Thank you so much for working on this. I merged it in #23816.

@meinac meinac deleted the action_pack_json_parser_bug branch February 23, 2016 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants