File tree Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Expand file tree Collapse file tree 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) {
3131 const toUrl = decodedBaseUrl . replace ( foundRule . from , toTarget )
3232
3333 try {
34- res . setHeader ( 'Location' , toUrl )
34+ res . setHeader ( 'Location' , encodeURI ( toUrl ) )
3535 } catch ( error ) {
3636 // Not passing the error as it's caused by URL that was user-provided so we
3737 // can't do anything about the error.
Original file line number Diff line number Diff line change 11module . exports = [
22 { from : '^/redirected' , to : '/' } ,
33 { from : / ^ \/ ä ß U < / , to : '/' } ,
4+ { from : '^/äöü$' , to : '/äßU<' } ,
45 { from : '^/many/(.*)$' , to : '/posts/abcde' } ,
56 { from : '^/mapped/(.*)$' , to : '/posts/$1' } ,
67 { from : '^/function$' , to : ( ) => '/' } ,
@@ -17,6 +18,7 @@ module.exports = [
1718 setTimeout ( ( ) => resolve ( `/posts/${ param } ` ) , 2000 )
1819 } )
1920 } ,
21+ { from : '^/errorInTo$' , to : '/mapped/\uD800ab\u0001/' } ,
2022 {
2123 from : '^/errorInToFunction$' ,
2224 to : ( ) => Promise . reject ( new Error ( 'forced error' ) )
Original file line number Diff line number Diff line change @@ -42,9 +42,19 @@ const testSuite = () => {
4242 expect ( html ) . toContain ( 'Works!' )
4343 } )
4444
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 ( ) => {
4656 const requestOptions = {
47- uri : url ( encodeURI ( '/mapped/ab\u0001' ) ) ,
57+ uri : url ( '/errorInTo' ) ,
4858 resolveWithFullResponse : true
4959 }
5060
You can’t perform that action at this time.
0 commit comments