Permalink
Browse files

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

  • Loading branch information...
1 parent 44d0625 commit b3936b96e518d845c5b69d1f1da8fa99918b3333 @tj tj committed Oct 16, 2012
Showing with 6 additions and 5 deletions.
  1. +2 −1 lib/response.js
  2. +4 −4 test/res.jsonp.js
View
@@ -234,7 +234,8 @@ res.jsonp = function(obj){
// jsonp
if (callback) {
this.set('Content-Type', 'text/javascript');
- body = callback.replace(/[^\[\]\w$.]/g, '') + '(' + body + ');';
+ var cb = callback.replace(/[^\[\]\w$.]/g, '');
+ body = cb + ' && ' + cb + '(' + body + ');';
}
return this.send(body);
View
@@ -16,7 +16,7 @@ describe('res', function(){
.get('/?callback=something')
.end(function(err, res){
res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');
- res.text.should.equal('something({"count":1});');
+ res.text.should.equal('something && something({"count":1});');
done();
})
})
@@ -34,7 +34,7 @@ describe('res', function(){
.get('/?clb=something')
.end(function(err, res){
res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');
- res.text.should.equal('something({"count":1});');
+ res.text.should.equal('something && something({"count":1});');
done();
})
})
@@ -50,7 +50,7 @@ describe('res', function(){
.get('/?callback=callbacks[123]')
.end(function(err, res){
res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');
- res.text.should.equal('callbacks[123]({"count":1});');
+ res.text.should.equal('callbacks[123] && callbacks[123]({"count":1});');
done();
})
})
@@ -66,7 +66,7 @@ describe('res', function(){
.get('/?callback=foo;bar()')
.end(function(err, res){
res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');
- res.text.should.equal('foobar({});');
+ res.text.should.equal('foobar && foobar({});');
done();
})
})

0 comments on commit b3936b9

Please sign in to comment.