Improved the renderers encoding by using the template encoding or encoding specified in a property

This commit is contained in:
Erik C. Thauvin 2023-03-25 15:46:05 -07:00
parent 538a8d35ae
commit 9738ecb0ba
34 changed files with 197 additions and 61 deletions

View file

@ -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("&lt;a test &amp;&gt;");
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&apos;s Café &amp; Bar");
}
@Test
void testHtmlEntities() {
assertThat(RenderUtils.htmlEntities(SAMPLE_GERMAN))