Skip to content
Myr

add cb && cb(payload) to `res.jsonp()`. Closes #1374

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent 44d0625 · Browse files · 2 files+6 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+6 added−5 removed

  • tests:+4 added−4 removed
  • other:+2 added−1 removed

2 files+6 added−5 removed

modified:lib/response.js+2 added-1 removed
232 unmodified lines
233 234 // jsonp235 if (callback) {236 this.set('Content-Type', 'text/javascript');237 body = callback.replace(/[^\[\]\w$.]/g, '') + '(' + body + ');';237 var cb = callback.replace(/[^\[\]\w$.]/g, '');238 body = cb + ' && ' + cb + '(' + body + ');';239 }240241 return this.send(body);242};
480 unmodified lines
modified:test/res.jsonp.js+4 added-4 removed
14 unmodified lines
15 request(app)16 .get('/?callback=something')17 .end(function(err, res){18 res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');19 res.text.should.equal('something({"count":1});');19 res.text.should.equal('something && something({"count":1});');20 done();21 })22 })23
9 unmodified lines
33 request(app)34 .get('/?clb=something')35 .end(function(err, res){36 res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');37 res.text.should.equal('something({"count":1});');37 res.text.should.equal('something && something({"count":1});');38 done();39 })40 }) 41
7 unmodified lines
49 request(app)50 .get('/?callback=callbacks[123]')51 .end(function(err, res){52 res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');53 res.text.should.equal('callbacks[123]({"count":1});');53 res.text.should.equal('callbacks[123] && callbacks[123]({"count":1});');54 done();55 })56 })57
7 unmodified lines
65 request(app)66 .get('/?callback=foo;bar()')67 .end(function(err, res){68 res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');69 res.text.should.equal('foobar({});');69 res.text.should.equal('foobar && foobar({});');70 done();71 })72 })73
147 unmodified lines