File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
libs/definitions/src/utils Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -117,5 +117,12 @@ describe('FieldUtils', () => {
117117 bar : 'BAR' ,
118118 } )
119119 } )
120+
121+ it ( 'should replace undefined template variables with empty string' , ( ) => {
122+ const res = replaceTemplateFields ( idsMap , { foo : 'Test {{ template.foo }}' } , { } )
123+ expect ( res ) . toEqual ( {
124+ foo : 'Test ' ,
125+ } )
126+ } )
120127 } )
121128} )
Original file line number Diff line number Diff line change @@ -106,14 +106,17 @@ export function replaceTemplateFields(
106106 for ( const match of matches ) {
107107 // replace fields that only contain a template variable (the interpolation is removed)
108108 if ( match [ 1 ] . trim ( ) . startsWith ( 'template.' ) ) {
109- newValue = newValue . replace ( match [ 0 ] , templateInputs [ match [ 1 ] . trim ( ) . replace ( 'template.' , '' ) ] )
109+ newValue = newValue . replace ( match [ 0 ] , templateInputs [ match [ 1 ] . trim ( ) . replace ( 'template.' , '' ) ] ?? '' )
110110 }
111111 // replace fields that contain template variables inside functions or other variables (the interpolation is kept)
112112 else {
113113 // replace "template." variables
114114 const templateRegex = / t e m p l a t e \. ( [ a - z A - Z 0 - 9 _ \[ \] \. ] + ) / g
115115 for ( const templateMatch of Array . from ( ( match [ 1 ] . match ( templateRegex ) as RegExpMatchArray ) ?? [ ] ) ) {
116- newValue = newValue . replace ( templateMatch , templateInputs [ templateMatch . trim ( ) . replace ( 'template.' , '' ) ] )
116+ newValue = newValue . replace (
117+ templateMatch ,
118+ templateInputs [ templateMatch . trim ( ) . replace ( 'template.' , '' ) ] ?? '' ,
119+ )
117120 }
118121 // replace old IDs
119122 const idRegex = / [ 0 - 9 a - f ] { 24 } / g
You can’t perform that action at this time.
0 commit comments