@@ -42,13 +42,29 @@ export function serializeToYaml(object: any, skipInvalid = false, noRefs = false
4242 } )
4343}
4444
45- export function removePassword ( input : string ) {
46- return input . replace ( / ( - S t r i n g | - P | p a s s : | \/ p | - p a s s | - - s e c r e t K e y | - - a c c e s s K e y | - p ) ( [ ^ ] + ) / g, ( match , p1 , p2 ) => {
47- if ( p1 . trim ( ) === "/p" && p2 . startsWith ( "\\\\Mac\\Host\\\\" ) ) {
48- // appx /p
49- return `${ p1 } ${ p2 } `
45+ export function removePassword ( input : string ) : string {
46+ const blockList = [ "--accessKey" , "--secretKey" , "-P" , "-p" , "-pass" , "-String" , "/p" , "pass:" ]
47+
48+ // Create a regex pattern that supports:
49+ // - space-separated unquoted values: --key value
50+ // - quoted values: --key "value with spaces" or 'value with spaces'
51+ const blockPattern = new RegExp ( `(${ blockList . map ( s => s . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ) . join ( "|" ) } )\\s*(?:(["'])(.*?)\\2|([^\\s]+))` , "g" )
52+
53+ input = input . replace ( blockPattern , ( _match , prefix , quote , quotedVal , unquotedVal ) => {
54+ const value = quotedVal ?? unquotedVal
55+
56+ if ( prefix . trim ( ) === "/p" && value . startsWith ( "\\\\Mac\\Host\\\\" ) ) {
57+ return `${ prefix } ${ quote ?? "" } ${ value } ${ quote ?? "" } `
5058 }
51- return `${ p1 } ${ createHash ( "sha256" ) . update ( p2 ) . digest ( "hex" ) } (sha256 hash)`
59+
60+ const hashed = createHash ( "sha256" ) . update ( value ) . digest ( "hex" )
61+ return `${ prefix } ${ quote ?? "" } ${ hashed } (sha256 hash)${ quote ?? "" } `
62+ } )
63+
64+ // Also handle `/b ... /c` block format
65+ return input . replace ( / ( \/ b \s + ) ( .* ?) ( \s + \/ c ) / g, ( _match , p1 , p2 , p3 ) => {
66+ const hashed = createHash ( "sha256" ) . update ( p2 ) . digest ( "hex" )
67+ return `${ p1 } ${ hashed } (sha256 hash)${ p3 } `
5268 } )
5369}
5470
0 commit comments