@@ -30,7 +30,10 @@ export function parseSecrets(raw: string | undefined): ParsedSecret[] {
3030 const trimmed = raw . trim ( ) ;
3131 if ( ! trimmed ) return [ ] ;
3232
33- const entries = trimmed . startsWith ( "{" ) ? parseJsonObject ( trimmed ) : parseBlockMap ( trimmed ) ;
33+ // For the JSON-form check we use the trimmed view, but the block-map parser
34+ // needs the original `raw` so trailing whitespace on the last line (which
35+ // could be part of a secret's value) is preserved.
36+ const entries = trimmed . startsWith ( "{" ) ? parseJsonObject ( trimmed ) : parseBlockMap ( raw ) ;
3437 for ( const { value } of entries ) {
3538 if ( value !== "" ) core . setSecret ( value ) ;
3639 }
@@ -83,7 +86,7 @@ function parseBlockMap(raw: string): ParsedSecret[] {
8386 }
8487
8588 const name = line . slice ( 0 , colon ) . trim ( ) ;
86- const value = stripQuotes ( line . slice ( colon + 1 ) . trim ( ) ) ;
89+ const value = parseValue ( line . slice ( colon + 1 ) ) ;
8790
8891 validateName ( name , `secrets line ${ i + 1 } ` ) ;
8992 if ( seen . has ( name ) ) {
@@ -95,14 +98,25 @@ function parseBlockMap(raw: string): ParsedSecret[] {
9598 return out ;
9699}
97100
98- function stripQuotes ( value : string ) : string {
99- if ( value . length < 2 ) return value ;
100- const first = value . charAt ( 0 ) ;
101- const last = value . charAt ( value . length - 1 ) ;
102- if ( ( first === '"' && last === '"' ) || ( first === "'" && last === "'" ) ) {
103- return value . slice ( 1 , - 1 ) ;
101+ /**
102+ * Extract a secret value from the substring after the first `:` separator.
103+ *
104+ * Strips leading whitespace (the canonical YAML `KEY: VALUE` separator) and
105+ * a matching pair of outer quotes if present. Trailing whitespace and inner
106+ * whitespace are preserved verbatim, so a secret value can contain any
107+ * characters; users that need leading or trailing whitespace must wrap the
108+ * value in matching single or double quotes.
109+ */
110+ function parseValue ( rest : string ) : string {
111+ const ltrimmed = rest . replace ( / ^ \s + / , "" ) ;
112+ if ( ltrimmed . length >= 2 ) {
113+ const first = ltrimmed . charAt ( 0 ) ;
114+ const last = ltrimmed . charAt ( ltrimmed . length - 1 ) ;
115+ if ( ( first === '"' && last === '"' ) || ( first === "'" && last === "'" ) ) {
116+ return ltrimmed . slice ( 1 , - 1 ) ;
117+ }
104118 }
105- return value ;
119+ return ltrimmed ;
106120}
107121
108122function validateName ( name : string , context : string ) : void {
0 commit comments