Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #5554 passing URL instances with new location encoding #5555

Merged
merged 1 commit into from
Mar 20, 2024
Merged
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
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.19.0 / 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('https://google.com/')).end();
});

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