Skip to content

Commit a003cfa

Browse files
committed
Allow passing non-strings to res.location with new encoding handling checks fixes #5554 #5555
1 parent a1fa90f commit a003cfa

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

History.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
unreleased changes
2+
==========
3+
4+
* Allow passing non-strings to res.location with new encoding handling checks
5+
16
4.19.0 / 2024-03-20
27
==========
38

lib/response.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ res.cookie = function (name, value, options) {
905905
*/
906906

907907
res.location = function location(url) {
908-
var loc = url;
908+
var loc = String(url);
909909

910910
// "back" is an alias for the referrer
911911
if (url === 'back') {

test/res.location.js

+15
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,20 @@ describe('res', function(){
145145
.expect(200, done)
146146
})
147147
})
148+
149+
if (typeof URL !== 'undefined') {
150+
it('should accept an instance of URL', function (done) {
151+
var app = express();
152+
153+
app.use(function(req, res){
154+
res.location(new URL('http://google.com/')).end();
155+
});
156+
157+
request(app)
158+
.get('/')
159+
.expect('Location', 'http://google.com/')
160+
.expect(200, done);
161+
});
162+
}
148163
})
149164
})

0 commit comments

Comments
 (0)