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

Calling reply without a payload on a JSONP route throws an error #3155

Closed
kschat opened this issue May 18, 2016 · 3 comments
Closed

Calling reply without a payload on a JSONP route throws an error #3155

kschat opened this issue May 18, 2016 · 3 comments
Labels
bug Bug or defect

Comments

@kschat
Copy link

kschat commented May 18, 2016

This only occurs if the query parameter containing the JSONP function name is given. Code to reproduce:

'use strict';

const hapi = require('hapi');
const server = new hapi.Server();

server.connection({ port: 4000 });

server.route({
  method: 'GET',
  path: '/test',
  config: {
    jsonp: 'callback',
    handler(request, reply) {
      return reply();
    }
  }
});

server.start(() => console.log('server started'));

Requesting /test works fine, but requesting /test?callback=cb throws the following error:

Debug: internal, implementation, error
    TypeError: Cannot read property 'replace' of null
    at internals.Response._prepare.internals.Response._processPrepare.internals.Response._marshal.internals.Payload.jsonp (/home/kyle/Workspace/hapi-bug/node_modules/hapi/lib/response.js:625:71)
    at /home/kyle/Workspace/hapi-bug/node_modules/hapi/lib/transmit.js:135:35
    at internals.Response._prepare.internals.Response._processPrepare.internals.Response._marshal.internals.Response._streamify (/home/kyle/Workspace/hapi-bug/node_modules/hapi/lib/response.js:529:12)
    at internals.Response._prepare.internals.Response._processPrepare.internals.Response._marshal.next [as _marshal] (/home/kyle/Workspace/hapi-bug/node_modules/hapi/lib/response.js:470:21)
    at /home/kyle/Workspace/hapi-bug/node_modules/hapi/lib/transmit.js:124:18
    at /home/kyle/Workspace/hapi-bug/node_modules/hapi/lib/transmit.js:509:20
    at Object.exports.parallel (/home/kyle/Workspace/hapi-bug/node_modules/hapi/node_modules/items/lib/index.js:47:9)
    at Object.exports.send.internals.marshal.internals.fail.internals.transmit.internals.state.Items.parallel [as state] (/home/kyle/Workspace/hapi-bug/node_modules/hapi/lib/transmit.js:502:11)
    at Object.exports.send.internals.marshal.internals.state [as marshal] (/home/kyle/Workspace/hapi-bug/node_modules/hapi/lib/transmit.js:98:15)
    at Object.exports.send.callback [as send] (/home/kyle/Workspace/hapi-bug/node_modules/hapi/lib/transmit.js:30:15)

I've been able to reproduce on 13.0.0 and 13.4.0, but haven't tested on any other versions.

@hueniverse hueniverse added the bug Bug or defect label May 19, 2016
@hueniverse
Copy link
Contributor

Can you PR a failing test?

@kschat
Copy link
Author

kschat commented May 20, 2016

Sure, I'll try to get that in today.

@kschat
Copy link
Author

kschat commented May 23, 2016

Looks like @nrotta beat me to the punch. If there's anything else I can do, please let me know.

hueniverse added a commit that referenced this issue Jul 5, 2016
Fixes #3155 - Calling reply without a payload on a JSONP route throws
@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants