Skip to content

Commit b06f533

Browse files
committed
fix #5554 passing URL instances with new locataion encoding
1 parent 084e365 commit b06f533

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/response.js

Lines changed: 1 addition & 1 deletion
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

Lines changed: 15 additions & 0 deletions
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)