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

The JSON API media type should only work with a JSON API handler #23712

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/http/mime_types.rb
Expand Up @@ -28,7 +28,7 @@

# http://www.ietf.org/rfc/rfc4627.txt
# http://www.json.org/JSONRequest.html
Mime::Type.register "application/json", :json, %w( text/x-json application/jsonrequest application/vnd.api+json )
Mime::Type.register "application/json", :json, %w( text/x-json application/jsonrequest )

Mime::Type.register "application/pdf", :pdf, [], %w(pdf)
Mime::Type.register "application/zip", :zip, [], %w(zip)
11 changes: 2 additions & 9 deletions actionpack/test/dispatch/request/json_params_parsing_test.rb
Expand Up @@ -37,9 +37,9 @@ def teardown
)
end

test "parses json params for application/vnd.api+json" do
test "does not parses unregistered media types such as application/vnd.api+json" do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rafaelfranca typo does not parses should be does not parse. Just leave it for someone else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change it quickly, but if you want to make a PR go ahead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's cleaner if you just fix it, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

assert_parses(
{"person" => {"name" => "David"}},
{},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept this test around both in case anyone is looking for json api support, and because I didn't see the behavior tested elsewhere.

However, I removed the test for rootless JSON as it duplicates what I left here and also isn't relevant to JSON API.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Make sense 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha, that was quick! you merged it right before I revised the commit message from 'I' to 'we' and fixed a typo. :) Thanks!

"{\"person\": {\"name\": \"David\"}}", { 'CONTENT_TYPE' => 'application/vnd.api+json' }
)
end
Expand Down Expand Up @@ -143,13 +143,6 @@ def teardown
)
end

test "parses json params for application/vnd.api+json" do
assert_parses(
{"user" => {"username" => "sikachu"}, "username" => "sikachu"},
"{\"username\": \"sikachu\"}", { 'CONTENT_TYPE' => 'application/vnd.api+json' }
)
end

test "parses json with non-object JSON content" do
assert_parses(
{"user" => {"_json" => "string content" }, "_json" => "string content" },
Expand Down