Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,10 @@ res.redirect = function redirect(url) {
deprecate('Status must be a number');
}

if (typeof address !== 'string' || address.length === 0) {
throw new TypeError('Redirect location must be a non-empty string');
}

// Set location header
address = this.location(address).get('Location');

Expand Down
12 changes: 12 additions & 0 deletions test/res.redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ describe('res', function(){
.expect('Location', 'https://google.com?q=%E2%98%83%20%C2%A710')
.expect(302, done)
})
it('should throw error for undefined redirect location', function () {
var app = express();

app.use(function (req, res) {
res.redirect(undefined);
});

request(app)
.get('/')
.expect(500);
});


it('should not touch already-encoded sequences in "url"', function (done) {
var app = express()
Expand Down