@@ -148,29 +148,25 @@ export class Job {
148
148
} ;
149
149
}
150
150
151
+ private static escape ( key : any , val : any ) {
152
+ if ( typeof ( val ) !== "string" ) return val ;
153
+ return val
154
+ . replace ( / [ \\ ] / g, '\\\\' )
155
+ . replace ( / [ \/ ] / g, '\\/' )
156
+ . replace ( / [ \b ] / g, '\\b' )
157
+ . replace ( / [ \f ] / g, '\\f' )
158
+ . replace ( / [ \n ] / g, '\\n' )
159
+ . replace ( / [ \r ] / g, '\\r' )
160
+ . replace ( / [ \t ] / g, '\\t' )
161
+ . replace ( / [ " ] / g, '\\"' )
162
+ . replace ( / \\ ' / g, "\\'" ) ;
163
+ }
164
+
151
165
public async init ( ) {
152
166
const allEnvs : { [ key : string ] : string } = { ...this . globals . variables || { } , ...this . variables , ...process . env , ...this . predefinedVariables } ;
153
- const envs : { [ key : string ] : string } = { }
154
-
155
- let command = 'printenv'
156
- for ( let i = 0 ; i < this . extendsDepth ; i ++ ) {
157
- command += ` | envsubst`
158
- }
167
+ const command = `echo '${ JSON . stringify ( allEnvs , Job . escape ) } ' | envsubst` ;
159
168
const res = await exec ( command , { env : allEnvs } ) ;
160
-
161
- const keysToSubst = Object . keys ( { ...this . globals . variables || { } , ...this . variables } ) ;
162
- for ( const line of res . stdout . split ( "\n" ) ) {
163
- const split = line . split ( '=' ) ;
164
- if ( ! split [ 1 ] ) {
165
- continue ;
166
- }
167
- if ( ! keysToSubst . includes ( split [ 0 ] ) ) {
168
- continue ;
169
- }
170
- envs [ split [ 0 ] ] = split [ 1 ] ;
171
- }
172
-
173
- this . envs = ( { ...envs , ...process . env , ...this . predefinedVariables } as any ) ;
169
+ this . envs = JSON . parse ( res . stdout ) ;
174
170
175
171
if ( ! this . rules ) {
176
172
return ;
0 commit comments