mirror of
https://github.com/expressjs/express.git
synced 2026-02-26 18:57:43 +00:00
Compare commits
2 Commits
v5.2.0
...
throw-redi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3981e29545 | ||
|
|
f636741bf8 |
@@ -825,6 +825,18 @@ res.redirect = function redirect(url) {
|
||||
address = arguments[1]
|
||||
}
|
||||
|
||||
if (!address) {
|
||||
throw new TypeError('url argument is required to res.redirect');
|
||||
}
|
||||
|
||||
if (typeof address !== 'string') {
|
||||
throw new TypeError('res.redirect: url must be a string');
|
||||
}
|
||||
|
||||
if (typeof status !== 'number') {
|
||||
throw new TypeError('res.redirect: status must be a number');
|
||||
}
|
||||
|
||||
// Set location header
|
||||
address = this.location(address).get('Location');
|
||||
|
||||
|
||||
@@ -19,6 +19,42 @@ describe('res', function(){
|
||||
.expect(302, done)
|
||||
})
|
||||
|
||||
it('should throw an error if the url is missing', function(done){
|
||||
var app = express();
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.redirect(undefined)
|
||||
})
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect(500, /url argument is required to res.redirect/, done)
|
||||
})
|
||||
|
||||
it('should throw an error if the url is not a string', function(done){
|
||||
var app = express();
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.redirect(['http://google.com'])
|
||||
})
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect(500, /res.redirect: url must be a string/, done)
|
||||
})
|
||||
|
||||
it('should throw an error if the status is not a number', function(done){
|
||||
var app = express();
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.redirect("300", 'http://google.com')
|
||||
})
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect(500, /res.redirect: status must be a number/, done)
|
||||
})
|
||||
|
||||
it('should encode "url"', function (done) {
|
||||
var app = express()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user