Skip to content

Commit

Permalink
Fixes #3155 - Calling reply without a payload on a JSONP route throws…
Browse files Browse the repository at this point in the history
… an error
  • Loading branch information
nrotta committed May 21, 2016
1 parent 6d2896b commit b7dbd2a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,6 @@ internals.Payload.prototype.jsonp = function (variable) {

this._sizeOffset = this._sizeOffset + variable.length + 7;
this._prefix = '/**/' + variable + '('; // '/**/' prefix prevents CVE-2014-4671 security exploit
this._data = Buffer.isBuffer(this._data) ? this._data : this._data.replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029');
this._data = (this._data === null || Buffer.isBuffer(this._data)) ? this._data : this._data.replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029');
this._suffix = ');';
};
20 changes: 20 additions & 0 deletions test/transmit.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,26 @@ describe('transmission', () => {
});
});

it('returns an JSONP response with no payload', (done) => {

const handler = function (request, reply) {

return reply();
};

const server = new Hapi.Server();
server.connection();
server.route({ method: 'GET', path: '/', config: { jsonp: 'callback', handler: handler } });

server.inject('/?callback=me', (res) => {

expect(res.payload).to.equal('/**/me();');
expect(res.headers['content-length']).to.equal(9);
expect(res.headers['content-type']).to.equal('text/javascript; charset=utf-8');
done();
});
});

it('returns an JSONP response (no charset)', (done) => {

const handler = function (request, reply) {
Expand Down

0 comments on commit b7dbd2a

Please sign in to comment.