Merge branch '4.1.x'

This commit is contained in:
Douglas Christopher Wilson 2014-05-08 14:45:47 -04:00
commit 0bbbc84959
6 changed files with 83 additions and 6 deletions

View File

@ -1,3 +1,9 @@
4.1.2 / 2014-05-08
==================
* fix `req.host` for IPv6 literals
* fix `res.jsonp` error if callback param is object
4.1.1 / 2014-04-27
==================
@ -46,6 +52,12 @@
- `app.route()` - Proxy to the app's `Router#route()` method to create a new route
- Router & Route - public API
3.5.3 / 2014-05-08
==================
* fix `req.host` for IPv6 literals
* fix `res.jsonp` error if callback param is object
3.5.2 / 2014-04-24
==================

View File

@ -348,7 +348,13 @@ req.__defineGetter__('host', function(){
var host = trustProxy && this.get('X-Forwarded-Host');
host = host || this.get('Host');
if (!host) return;
return host.split(':')[0];
var offset = host[0] === '['
? host.indexOf(']') + 1
: 0;
var index = host.indexOf(':', offset);
return ~index
? host.substring(0, index)
: host;
});
/**

View File

@ -232,9 +232,13 @@ res.jsonp = function(obj){
// content-type
this.get('Content-Type') || 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 + ');';

View File

@ -1,7 +1,7 @@
{
"name": "express",
"description": "Sinatra inspired web development framework",
"version": "4.1.1",
"version": "4.1.2",
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"contributors": [
{

View File

@ -18,6 +18,19 @@ describe('req', function(){
.expect('example.com', done);
})
it('should strip port number', function(done){
var app = express();
app.use(function(req, res){
res.end(req.host);
});
request(app)
.post('/')
.set('Host', 'example.com:3000')
.expect('example.com', done);
})
it('should return undefined otherwise', function(done){
var app = express();
@ -30,5 +43,31 @@ describe('req', function(){
.post('/')
.expect('undefined', done);
})
it('should work with IPv6 Host', function(done){
var app = express();
app.use(function(req, res){
res.end(req.host);
});
request(app)
.post('/')
.set('Host', '[::1]')
.expect('[::1]', done);
})
it('should work with IPv6 Host and port', function(done){
var app = express();
app.use(function(req, res){
res.end(req.host);
});
request(app)
.post('/')
.set('Host', '[::1]:3000')
.expect('[::1]', done);
})
})
})

View File

@ -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');
res.text.should.equal('{"count":1}');
done();
})
})
it('should allow renaming callback', function(done){
var app = express();
@ -205,7 +221,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();
@ -224,7 +240,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();