Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from gr2m/master
Browse files Browse the repository at this point in the history
ignore charset=utf-8 media type parameter
  • Loading branch information
wraithgar committed Jan 2, 2016
2 parents 6c37ae4 + 367280b commit 9fd6e82
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ internals.onPreHandler = function (request, reply) {
if (contentType) {
var contentMedia = MediaType.fromString(contentType);

// Ignore charset=UTF-8 media type parameter
// https://github.com/json-api/json-api/issues/837
if (contentMedia.parameters.charset === 'UTF-8') {
delete contentMedia.parameters.charset
}

//Hapi does not allow application/* w/o json suffix so we don't need to test for it
if (contentMedia.type !== 'application' || contentMedia.subtype !== 'vnd.api' || Object.keys(contentMedia.parameters).length > 0) {

Expand Down
19 changes: 19 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,25 @@ lab.experiment('hapi-json-api', function () {
done();
});
});

// https://github.com/json-api/json-api/issues/837
lab.test('media type is charset=utf-8', function (done) {

var options = {
method: 'POST', url: '/post',
headers: {
accept: 'application/vnd.api+json',
'content-type': 'application/vnd.api+json; charset=UTF-8'
}
};
server.inject(options, function (response) {

var payload = JSON.parse(response.payload);
Code.expect(response.statusCode).to.equal(200);
Code.expect(payload).to.deep.include({data: {id: 'post'}});
done();
});
});
});

lab.experiment('Boom replies', function () {
Expand Down

0 comments on commit 9fd6e82

Please sign in to comment.