File tree 3 files changed +15
-3
lines changed
3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ module.exports = function (options) {
31
31
const toUrl = decodedBaseUrl . replace ( foundRule . from , toTarget )
32
32
33
33
try {
34
- res . setHeader ( 'Location' , toUrl )
34
+ res . setHeader ( 'Location' , encodeURI ( toUrl ) )
35
35
} catch ( error ) {
36
36
// Not passing the error as it's caused by URL that was user-provided so we
37
37
// can't do anything about the error.
Original file line number Diff line number Diff line change 1
1
module . exports = [
2
2
{ from : '^/redirected' , to : '/' } ,
3
3
{ from : / ^ \/ ä ß U < / , to : '/' } ,
4
+ { from : '^/äöü$' , to : '/äßU<' } ,
4
5
{ from : '^/many/(.*)$' , to : '/posts/abcde' } ,
5
6
{ from : '^/mapped/(.*)$' , to : '/posts/$1' } ,
6
7
{ from : '^/function$' , to : ( ) => '/' } ,
@@ -17,6 +18,7 @@ module.exports = [
17
18
setTimeout ( ( ) => resolve ( `/posts/${ param } ` ) , 2000 )
18
19
} )
19
20
} ,
21
+ { from : '^/errorInTo$' , to : '/mapped/\uD800ab\u0001/' } ,
20
22
{
21
23
from : '^/errorInToFunction$' ,
22
24
to : ( ) => Promise . reject ( new Error ( 'forced error' ) )
Original file line number Diff line number Diff line change @@ -42,9 +42,19 @@ const testSuite = () => {
42
42
expect ( html ) . toContain ( 'Works!' )
43
43
} )
44
44
45
- test ( 'redirect error with control character' , async ( ) => {
45
+ test ( 'non-ascii redirect to another non-ascii url' , async ( ) => {
46
+ const html = await get ( '/äöü' )
47
+ expect ( html ) . toContain ( 'Works!' )
48
+ } )
49
+
50
+ test ( 'redirect with control character' , async ( ) => {
51
+ const html = await get ( encodeURI ( '/mapped/ab\u0001' ) )
52
+ expect ( html ) . toContain ( 'ab' )
53
+ } )
54
+
55
+ test ( 'redirect error due to malformatted target url' , async ( ) => {
46
56
const requestOptions = {
47
- uri : url ( encodeURI ( '/mapped/ab\u0001' ) ) ,
57
+ uri : url ( '/errorInTo' ) ,
48
58
resolveWithFullResponse : true
49
59
}
50
60
You can’t perform that action at this time.
0 commit comments