Skip to content

Commit a0311e6

Browse files
authored
Merge pull request #804 from iosadchii/fix-media-type-matching
Fix media type matching
2 parents cdb933d + 2ec9ca7 commit a0311e6

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/jsonapi/acts_as_resource_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module JSONAPI
44
module ActsAsResourceController
5-
MEDIA_TYPE_MATCHER = /(.+".+"[^,]*|[^,]+)/
5+
MEDIA_TYPE_MATCHER = /.+".+"[^,]*|[^,]+/
66
ALL_MEDIA_TYPES = '*/*'
77

88
def self.included(base)
@@ -169,7 +169,7 @@ def valid_accept_media_type?
169169

170170
def media_types_for(header)
171171
(request.headers[header] || '')
172-
.match(MEDIA_TYPE_MATCHER)
172+
.scan(MEDIA_TYPE_MATCHER)
173173
.to_a
174174
.map(&:strip)
175175
end

test/integration/requests/request_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ def test_get_camelized_route_and_links
9393
JSONAPI.configuration = original_config
9494
end
9595

96+
def test_get_accepting_multiple_content_types
97+
get '/posts', headers:
98+
{
99+
'Accept' => "application/json, #{JSONAPI::MEDIA_TYPE}, */*"
100+
}
101+
assert_equal 200, status
102+
end
103+
96104
def test_put_single_without_content_type
97105
put '/posts/3', params:
98106
{

0 commit comments

Comments
 (0)