File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -84,6 +84,11 @@ describe('sanitizeUrl', () => {
8484 const result = sanitizeUrl ( 'https://example.com?empty&hasvalue=test' )
8585 expect ( result ) . toBe ( 'https://example.com/?empty&hasvalue=test' )
8686 } )
87+
88+ it ( 'should encode basic auth' , ( ) => {
89+ const result = sanitizeUrl ( 'http://user$(calc)r:pass$(calc)word@domain.com' )
90+ expect ( result ) . toBe ( 'http://user%24(calc)r:pass%24(calc)word@domain.com/' )
91+ } )
8792 } )
8893
8994 describe ( 'should handle complex URLs' , ( ) => {
Original file line number Diff line number Diff line change @@ -722,6 +722,8 @@ export function sanitizeUrl(raw: string) {
722722 if ( url . hostname !== encodeURIComponent ( url . hostname ) ) abort ( )
723723
724724 // Forcibly sanitise all the pieces of the URL
725+ if ( url . username ) url . username = encodeURIComponent ( url . username )
726+ if ( url . password ) url . password = encodeURIComponent ( url . password )
725727 url . pathname = url . pathname . slice ( 0 , 1 ) + encodeURIComponent ( url . pathname . slice ( 1 ) ) . replace ( / % 2 f / ig, '/' )
726728 url . search = url . search . slice ( 0 , 1 ) + Array . from ( url . searchParams . entries ( ) ) . map ( sanitizeParam ) . join ( '&' )
727729 url . hash = url . hash . slice ( 0 , 1 ) + encodeURIComponent ( url . hash . slice ( 1 ) )
You can’t perform that action at this time.
0 commit comments