File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -469,11 +469,13 @@ export function buildIgnorePattern(ignorePatterns: Array<string>) {
469469}
470470
471471export function replaceEnvVariables ( value : string , { env} : { env : { [ key : string ] : string | undefined } } ) {
472- const regex = / \$ { (?< variableName > [ \d \w _ ] + ) (?< colon > : ) ? (?: - (?< fallback > [ ^ } ] * ) ) ? } / g;
472+ const regex = / \\ ? \ ${ (?< variableName > [ \d \w _ ] + ) (?< colon > : ) ? (?: - (?< fallback > [ ^ } ] * ) ) ? } / g;
473473
474- return value . replace ( regex , ( ...args ) => {
475- const { variableName, colon, fallback} = args [ args . length - 1 ] ;
474+ return value . replace ( regex , ( match , ...args ) => {
475+ if ( match . startsWith ( `\\` ) )
476+ return match . slice ( 1 ) ;
476477
478+ const { variableName, colon, fallback} = args [ args . length - 1 ] ;
477479 const variableExist = Object . hasOwn ( env , variableName ) ;
478480 const variableValue = env [ variableName ] ;
479481
Original file line number Diff line number Diff line change @@ -26,6 +26,20 @@ describe(`miscUtils`, () => {
2626 ) ,
2727 ) . toBe ( `VAR_A: ValueA, VAR_B: ValueB` ) ;
2828 } ) ;
29+
30+ it ( `should not replace escaped environment variables` , ( ) => {
31+ expect (
32+ miscUtils . replaceEnvVariables (
33+ `VAR_A: \\\${VAR_A}, VAR_B: \\\${VAR_B}` ,
34+ {
35+ env : {
36+ VAR_A : `ValueA` ,
37+ VAR_B : `ValueB` ,
38+ } ,
39+ } ,
40+ ) ,
41+ ) . toBe ( `VAR_A: \${VAR_A}, VAR_B: \${VAR_B}` ) ;
42+ } ) ;
2943 } ) ;
3044
3145 describe ( `mapAndFind` , ( ) => {
You can’t perform that action at this time.
0 commit comments