Browse files

escape res.redirect() link

  • Loading branch information...
1 parent 4892305 commit bac0c646338f91108273bb858f0b1dd7f2ec6bd4 @tj tj committed Aug 3, 2012
Showing with 19 additions and 1 deletion.
  1. +2 −1 lib/response.js
  2. +17 −0 test/res.redirect.js
View
3 lib/response.js
@@ -621,7 +621,8 @@ res.redirect = function(url){
},
html: function(){
- body = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + url + '">' + url + '</a></p>';
+ var u = utils.escape(url);
+ body = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>';
},
default: function(){
View
17 test/res.redirect.js
@@ -232,6 +232,23 @@ describe('res', function(){
done();
})
})
+
+ it('should escape the url', function(done){
+ var app = express();
+
+ app.use(function(req, res){
+ res.redirect('<lame>');
+ });
+
+ request(app)
+ .get('/')
+ .set('Host', 'http://example.com')
+ .set('Accept', 'text/html')
+ .end(function(err, res){
+ res.text.should.equal('<p>Moved Temporarily. Redirecting to <a href="//http://example.com/&lt;lame&gt;">//http://example.com/&lt;lame&gt;</a></p>');
+ done();
+ })
+ })
})
describe('when accepting text', function(){

0 comments on commit bac0c64

Please sign in to comment.