Improved the renderers encoding by using the template encoding or encoding specified in a property
This commit is contained in:
parent
538a8d35ae
commit
9738ecb0ba
34 changed files with 197 additions and 61 deletions
|
@ -19,6 +19,8 @@ package rife.render;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class TestRenderUtils {
|
||||
|
@ -35,6 +37,21 @@ class TestRenderUtils {
|
|||
.isEqualTo(TestCase.SAMPLE_TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEncode() {
|
||||
var p = new Properties();
|
||||
p.put(RenderUtils.ENCODING_PROPERTY, "html");
|
||||
assertThat(RenderUtils.encode("<a test &>", p)).as("html").isEqualTo("<a test &>");
|
||||
p.put(RenderUtils.ENCODING_PROPERTY, "js");
|
||||
assertThat(RenderUtils.encode("\"test'", p)).as("js").isEqualTo("\\\"test\\'");
|
||||
p.put(RenderUtils.ENCODING_PROPERTY, "unicode");
|
||||
assertThat(RenderUtils.encode("test", p)).as("unicode").isEqualTo("\\u0074\\u0065\\u0073\\u0074");
|
||||
p.put(RenderUtils.ENCODING_PROPERTY, "url");
|
||||
assertThat(RenderUtils.encode("a = test", p)).as("url").isEqualTo("a%20%3D%20test");
|
||||
p.put(RenderUtils.ENCODING_PROPERTY, "xml");
|
||||
assertThat(RenderUtils.encode("Joe's Café & Bar", p)).as("xml").isEqualTo("Joe's Café & Bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHtmlEntities() {
|
||||
assertThat(RenderUtils.htmlEntities(SAMPLE_GERMAN))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue