@@ -10,7 +10,14 @@ describe('ctx.redirect(url)', () => {
10
10
it ( 'should redirect to the given url' , ( ) => {
11
11
const ctx = context ( ) ;
12
12
ctx . redirect ( 'http://google.com' ) ;
13
- assert . strictEqual ( ctx . response . header . location , 'http://google.com' ) ;
13
+ assert . strictEqual ( ctx . response . header . location , 'http://google.com/' ) ;
14
+ assert . strictEqual ( ctx . status , 302 ) ;
15
+ } ) ;
16
+
17
+ it ( 'should formatting url before redirect' , ( ) => {
18
+ const ctx = context ( ) ;
19
+ ctx . redirect ( 'http://google.com\\@apple.com' ) ;
20
+ assert . strictEqual ( ctx . response . header . location , 'http://google.com/@apple.com' ) ;
14
21
assert . strictEqual ( ctx . status , 302 ) ;
15
22
} ) ;
16
23
@@ -66,7 +73,7 @@ describe('ctx.redirect(url)', () => {
66
73
ctx . header . accept = 'text/html' ;
67
74
ctx . redirect ( url ) ;
68
75
assert . strictEqual ( ctx . response . header [ 'content-type' ] , 'text/html; charset=utf-8' ) ;
69
- assert . strictEqual ( ctx . body , `Redirecting to <a href="${ url } ">${ url } </a>.` ) ;
76
+ assert . strictEqual ( ctx . body , `Redirecting to <a href="${ url } / ">${ url } / </a>.` ) ;
70
77
} ) ;
71
78
72
79
it ( 'should escape the url' , ( ) => {
@@ -86,17 +93,17 @@ describe('ctx.redirect(url)', () => {
86
93
const url = 'http://google.com' ;
87
94
ctx . header . accept = 'text/plain' ;
88
95
ctx . redirect ( url ) ;
89
- assert . strictEqual ( ctx . body , `Redirecting to ${ url } .` ) ;
96
+ assert . strictEqual ( ctx . body , `Redirecting to ${ url } / .` ) ;
90
97
} ) ;
91
98
} ) ;
92
99
93
100
describe ( 'when status is 301' , ( ) => {
94
101
it ( 'should not change the status code' , ( ) => {
95
102
const ctx = context ( ) ;
96
- const url = 'http://google.com' ;
103
+ const url = 'http://google.com/ ' ;
97
104
ctx . status = 301 ;
98
105
ctx . header . accept = 'text/plain' ;
99
- ctx . redirect ( 'http://google.com' ) ;
106
+ ctx . redirect ( url ) ;
100
107
assert . strictEqual ( ctx . status , 301 ) ;
101
108
assert . strictEqual ( ctx . body , `Redirecting to ${ url } .` ) ;
102
109
} ) ;
@@ -108,19 +115,19 @@ describe('ctx.redirect(url)', () => {
108
115
const url = 'http://google.com' ;
109
116
ctx . status = 304 ;
110
117
ctx . header . accept = 'text/plain' ;
111
- ctx . redirect ( 'http://google.com' ) ;
118
+ ctx . redirect ( url ) ;
112
119
assert . strictEqual ( ctx . status , 302 ) ;
113
- assert . strictEqual ( ctx . body , `Redirecting to ${ url } .` ) ;
120
+ assert . strictEqual ( ctx . body , `Redirecting to ${ url } / .` ) ;
114
121
} ) ;
115
122
} ) ;
116
123
117
124
describe ( 'when content-type was present' , ( ) => {
118
125
it ( 'should overwrite content-type' , ( ) => {
119
126
const ctx = context ( ) ;
120
127
ctx . body = { } ;
121
- const url = 'http://google.com' ;
128
+ const url = 'http://google.com/foo/bar ' ;
122
129
ctx . header . accept = 'text/plain' ;
123
- ctx . redirect ( 'http://google.com' ) ;
130
+ ctx . redirect ( url ) ;
124
131
assert . strictEqual ( ctx . status , 302 ) ;
125
132
assert . strictEqual ( ctx . body , `Redirecting to ${ url } .` ) ;
126
133
assert . strictEqual ( ctx . type , 'text/plain' ) ;
0 commit comments