@@ -54,22 +54,23 @@ export function redactConnectionString(
5454 return parsed . redact ( options ) . toString ( ) . replace ( / _ _ _ c r e d e n t i a l s _ _ _ / g, replacementString ) ;
5555 }
5656
57- const regexes : ( RegExp | null ) [ ] = [
57+ // Note: The regexes here used to use lookbehind assertions, but we dropped that since
58+ // we need to support older browsers here.
59+ const R = replacementString ; // alias for conciseness
60+ const replacements : ( ( uri : string ) => string ) [ ] = [
5861 // Username and password
59- redactUsernames ? / (?< = \/ \/ ) ( .* ) (? = @ ) / g : / (?< = \/ \/ [ ^ @ ] + : ) ( .* ) (? = @ ) / g,
62+ uri => uri . replace ( redactUsernames ? / ( \/ \/ ) ( .* ) ( @ ) / g : / ( \/ \/ [ ^ @ ] + : ) ( .* ) ( @ ) / g, `$1 ${ R } $3` ) ,
6063 // AWS IAM Session Token as part of query parameter
61- / (?< = A W S _ S E S S I O N _ T O K E N ( : | % 3 A ) ) ( [ ^ , & ] + ) / gi,
64+ uri => uri . replace ( / ( A W S _ S E S S I O N _ T O K E N ( : | % 3 A ) ) ( [ ^ , & ] + ) / gi, `$1 ${ R } ` ) ,
6265 // tlsCertificateKeyFilePassword query parameter
63- / (?< = t l s C e r t i f i c a t e K e y F i l e P a s s w o r d = ) ( [ ^ & ] + ) / gi,
66+ uri => uri . replace ( / ( t l s C e r t i f i c a t e K e y F i l e P a s s w o r d = ) ( [ ^ & ] + ) / gi, `$1 ${ R } ` ) ,
6467 // proxyUsername query parameter
65- redactUsernames ? / (?< = p r o x y U s e r n a m e = ) ( [ ^ & ] + ) / gi : null ,
68+ uri => redactUsernames ? uri . replace ( / ( p r o x y U s e r n a m e = ) ( [ ^ & ] + ) / gi, `$1 ${ R } ` ) : uri ,
6669 // proxyPassword query parameter
67- / (?< = p r o x y P a s s w o r d = ) ( [ ^ & ] + ) / gi
70+ uri => uri . replace ( / ( p r o x y P a s s w o r d = ) ( [ ^ & ] + ) / gi, `$1 ${ R } ` )
6871 ] ;
69- for ( const r of regexes ) {
70- if ( r !== null ) {
71- uri = uri . replace ( r , replacementString ) ;
72- }
72+ for ( const replacer of replacements ) {
73+ uri = replacer ( uri ) ;
7374 }
7475 return uri ;
7576}
0 commit comments