File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,13 @@ describe('ctx.redirect(url)', () => {
20
20
assert . strictEqual ( ctx . status , 302 )
21
21
} )
22
22
23
+ it ( 'should formatting url before redirect' , ( ) => {
24
+ const ctx = context ( )
25
+ ctx . redirect ( 'HTTP://google.com\\@apple.com' )
26
+ assert . strictEqual ( ctx . response . header . location , 'http://google.com/@apple.com' )
27
+ assert . strictEqual ( ctx . status , 302 )
28
+ } )
29
+
23
30
it ( 'should auto fix not encode url' , done => {
24
31
const app = new Koa ( )
25
32
Original file line number Diff line number Diff line change @@ -266,7 +266,7 @@ module.exports = {
266
266
redirect ( url , alt ) {
267
267
// location
268
268
if ( url === 'back' ) url = this . ctx . get ( 'Referrer' ) || alt || '/'
269
- if ( url . startsWith ( ' https://' ) || url . startsWith ( 'http://' ) ) {
269
+ if ( / ^ h t t p s ? : \/ \/ / i . test ( url ) ) {
270
270
// formatting url again avoid security escapes
271
271
url = new URL ( url ) . toString ( )
272
272
}
You can’t perform that action at this time.
0 commit comments