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