77 "net/http"
88 "os"
99 "os/exec"
10+ "regexp"
1011 "slices"
1112 "strings"
1213
@@ -43,6 +44,8 @@ func (e EnvVars) GetOutput() OutputList {
4344
4445type Secrets map [string ]string
4546
47+ var shellvar_regexp = regexp .MustCompile ("^[_A-Za-z][A-Za-z0-9_]*$" )
48+
4649func (s Secrets ) GetOutput (ctx context.Context , r * Reader ) (OutputList , error ) {
4750 // Read it like a kv secrets where all keys are "value"
4851 kvSecrets := KVSecrets {}
@@ -245,8 +248,10 @@ func (o OutputList) Exec(shell_cmd string) int {
245248 }
246249
247250 for _ , out := range o {
248- s := fmt .Sprintf ("%s=%s" , out .Key , out .Value )
249- cmd .Env = append (cmd .Environ (), s )
251+ if shellvar_regexp .MatchString (out .Key ) {
252+ s := fmt .Sprintf ("%s=%s" , out .Key , out .Value )
253+ cmd .Env = append (cmd .Environ (), s )
254+ }
250255 }
251256
252257 cmd .Stdin = os .Stdin
@@ -265,19 +270,19 @@ func (o OutputList) Exec(shell_cmd string) int {
265270
266271func (o OutputList ) Print (showComments bool ) {
267272 for _ , out := range o {
268- keySpace := ""
269- nl := false
270- if out . Key != "" {
271- fmt . Printf ( "export %s=%q" , out . Key , out . Value )
272- keySpace = " "
273- nl = true
274- }
275- if out . Comment != "" && showComments {
276- fmt . Printf ( "%s# %s" , keySpace , out . Comment )
277- nl = true
278- }
279- if nl {
280- fmt . Println ()
273+ if out . Key == "" {
274+ if showComments && out . Comment != "" {
275+ fmt . Printf ( "# %s \n " , out . Comment )
276+ }
277+ } else {
278+ /* silently discards variable names that are not shell safe */
279+ if shellvar_regexp . MatchString ( out . Key ) {
280+ fmt . Printf ( "export %s=%q" , out . Key , out . Value )
281+ if out . Comment != "" && showComments {
282+ fmt . Printf ( " # %s" , out . Comment )
283+ }
284+ fmt . Println ()
285+ }
281286 }
282287 }
283288}
0 commit comments