Skip to content

Commit

Permalink
fix #5554 passing URL instances with new locataion encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleytodd committed Mar 20, 2024
1 parent 11f2b1d commit 51584c7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
unreleased changes
==========

* Allow passing non-strings to res.location with new encoding handling checks

4.18.3 / 2024-03-20
==========

Expand Down
2 changes: 1 addition & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ res.cookie = function (name, value, options) {
*/

res.location = function location(url) {
var loc = url;
var loc = String(url);

// "back" is an alias for the referrer
if (url === 'back') {
Expand Down
15 changes: 15 additions & 0 deletions test/res.location.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,20 @@ describe('res', function(){
.expect(200, done)
})
})

if (typeof URL !== 'undefined') {
it('should accept an instance of URL', function (done) {
var app = express();

app.use(function(req, res){
res.location(new URL('http://google.com/')).end();
});

request(app)
.get('/')
.expect('Location', 'http://google.com/')
.expect(200, done);
});
}
})
})

0 comments on commit 51584c7

Please sign in to comment.