Skip to content

Commit

Permalink
BL-1140 Recursively replace placeholder values
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeers committed Feb 28, 2025
1 parent 6fcb73e commit ca2579d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ public ModuleConfig process( IStruct config ) {
this.settings = StructCaster.cast( config.getOrDefault( Key.settings, new Struct() ) );
// Process placeholders
this.settings.forEach( ( key, value ) -> {
if ( value instanceof String ) {
this.settings.put( key, PlaceholderHelper.resolve( value ) );
} else {
this.settings.put( key, value );
}
this.settings.put( key, PlaceholderHelper.resolveAll( value ) );
} );

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import ortus.boxlang.runtime.BoxRuntime;
import ortus.boxlang.runtime.dynamic.casters.StringCaster;
import ortus.boxlang.runtime.scopes.Key;
import ortus.boxlang.runtime.types.Array;
import ortus.boxlang.runtime.types.IStruct;
import ortus.boxlang.runtime.types.Struct;
import ortus.boxlang.runtime.types.exceptions.BoxRuntimeException;
Expand Down Expand Up @@ -162,6 +164,32 @@ public static String resolve( Object input ) {
return resolve( StringCaster.cast( input ) );
}

/**
* Recursively replace all placeholders throughout a tree made up of BoxLang Arrays and Structs
*
* @param input The Object to Resolve
*
* @return The Resolved tree
*
*/
public static <T> T resolveAll( T object ) {
if ( object instanceof Struct struct ) {
for ( Key key : struct.keySet() ) {
struct.put( key, PlaceholderHelper.resolveAll( struct.get( key ) ) );
}

return object;
} else if ( object instanceof Array array ) {
for ( int i = 0; i < array.size(); i++ ) {
array.set( i, PlaceholderHelper.resolveAll( array.get( i ) ) );
}

return object;
}

return ( T ) resolve( object );
}

/**
* Escape meta characters in the replacement string. In Java, the replacement
* string is treated as a regular expression and meta characters like "$" or
Expand Down

0 comments on commit ca2579d

Please # to comment.