Add ability to pass CharSequence instead of forcing String for context variable.
java.lang.String is immutable and cannot be overwritten by user. When passing sensitive data as context variable String remains in memory until GC removes it. CharSequence allows user to provide his own implementation and overwrite data as needed.
This commit is contained in:
@@ -17,9 +17,6 @@ import java.util.Optional;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Mustache tests that can only be run on the JVM. Most tests should go in BaseMustacheTest so
|
||||
@@ -54,6 +51,14 @@ public class MustacheTest extends SharedTests
|
||||
});
|
||||
}
|
||||
|
||||
@Test public void testCharSequenceVariable() {
|
||||
Map<String, CharSequence> ctx = new HashMap<>();
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("bar");
|
||||
ctx.put("foo", stringBuffer);
|
||||
test("bar", "{{foo}}", ctx);
|
||||
}
|
||||
|
||||
public interface HasDefault {
|
||||
default String getFoo () { return "bar"; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user