From 25f4582ff8d3d09786c4a11968766416fa6aa9fd Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Sat, 2 Jan 2016 15:42:23 +0100 Subject: [PATCH 1/2] test: ignore charset=utf-8 media type parameter --- test/index.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/index.js b/test/index.js index 48e2244..ead26ce 100644 --- a/test/index.js +++ b/test/index.js @@ -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 () { From 367280b01993d216073c5b0ea2c8a6bf4b4c70ba Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Sat, 2 Jan 2016 15:42:39 +0100 Subject: [PATCH 2/2] fix: ignore charset=utf-8 media type parameter --- lib/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/index.js b/lib/index.js index 660d0e8..6708f12 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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) {