Fix bug in placeholder replacement

This commit is contained in:
0xb00bface 2021-05-15 19:32:21 +02:00
parent 7d73f57f36
commit 5ef448fa14
2 changed files with 11 additions and 0 deletions

View File

@ -76,6 +76,8 @@ public abstract class AbstractPlaceholderAwarePostProcessor extends AbstractPost
if (questionMark > 0) {
placeholderName = placeholder.substring(2, questionMark);
defaultValue = placeholder.substring(questionMark + 1, placeholder.length() - 1);
} else {
defaultValue = "";
}
int bracket = placeholder.indexOf('(');
if (bracket > 0) {

View File

@ -1,6 +1,8 @@
package ctbrec.recorder.postprocessing;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.io.IOException;
import java.time.ZoneId;
@ -150,4 +152,11 @@ public class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest {
input = "asdf_${modelGroupName?${utcDateTime?anonymous}}_asdf";
assertEquals("asdf_anonymous_asdf", placeHolderAwarePp.fillInPlaceHolders(input, ctx));
}
@Test
public void testMissingValueForPlaceholder() throws IOException {
String input = "asdf_${modelNotes}_asdf";
when(config.getModelNotes(any())).thenReturn(null);
assertEquals("asdf__asdf", placeHolderAwarePp.fillInPlaceHolders(input, createPostProcessingContext(rec, null, config)));
}
}