mirror of
https://github.com/zebrajr/express.git
synced 2026-01-15 12:15:27 +00:00
add cb && cb(payload) to res.jsonp(). Closes #1374
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user