mirror of
https://github.com/zebrajr/express.git
synced 2026-01-15 12:15:27 +00:00
@@ -2,6 +2,7 @@
|
||||
=====
|
||||
|
||||
* fix `req.host` for IPv6 literals
|
||||
* fix `res.jsonp` error if callback param is object
|
||||
|
||||
3.5.2 / 2014-04-24
|
||||
==================
|
||||
|
||||
@@ -237,9 +237,13 @@ res.jsonp = function(obj){
|
||||
this.charset = this.charset || 'utf-8';
|
||||
this.set('Content-Type', 'application/json');
|
||||
|
||||
// fixup callback
|
||||
if (Array.isArray(callback)) {
|
||||
callback = callback[0];
|
||||
}
|
||||
|
||||
// jsonp
|
||||
if (callback) {
|
||||
if (Array.isArray(callback)) callback = callback[0];
|
||||
if (callback && 'string' === typeof callback) {
|
||||
this.set('Content-Type', 'text/javascript');
|
||||
var cb = callback.replace(/[^\[\]\w$.]/g, '');
|
||||
body = 'typeof ' + cb + ' === \'function\' && ' + cb + '(' + body + ');';
|
||||
|
||||
@@ -37,6 +37,22 @@ describe('res', function(){
|
||||
})
|
||||
})
|
||||
|
||||
it('should ignore object callback parameter with jsonp', function(done){
|
||||
var app = express();
|
||||
|
||||
app.use(function(req, res){
|
||||
res.jsonp({ count: 1 });
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/?callback[a]=something')
|
||||
.end(function(err, res){
|
||||
res.headers.should.have.property('content-type', 'application/json; charset=utf-8');
|
||||
res.text.should.equal('{"count":1}');
|
||||
done();
|
||||
})
|
||||
})
|
||||
|
||||
it('should allow renaming callback', function(done){
|
||||
var app = express();
|
||||
|
||||
@@ -212,7 +228,7 @@ describe('res', function(){
|
||||
})
|
||||
})
|
||||
|
||||
describe('.json(status, object)', function(){
|
||||
describe('.jsonp(status, object)', function(){
|
||||
it('should respond with json and set the .statusCode', function(done){
|
||||
var app = express();
|
||||
|
||||
@@ -231,7 +247,7 @@ describe('res', function(){
|
||||
})
|
||||
})
|
||||
|
||||
describe('.json(object, status)', function(){
|
||||
describe('.jsonp(object, status)', function(){
|
||||
it('should respond with json and set the .statusCode for backwards compat', function(done){
|
||||
var app = express();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user