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

@ -28,6 +28,10 @@ class TestEncode {
var t = TemplateFactory.TXT.get("encodeBase64");
t.setValue(TestCase.FOO, TestCase.SAMPLE_TEXT);
assertThat(t.getContent()).isEqualTo(t.getValue(TestCase.FOO) + ": VGhpcyBpcyBhIHRlc3Qu");
t = TemplateFactory.HTML.get("encodeBase64");
t.setValue(TestCase.FOO, TestCase.SAMPLE_TEXT + " URL Encoded.");
assertThat(t.getContent()).as("with URL encoding").contains("VGhpcyBpcyBhIHRlc3QuIFVSTCBFbmNvZGVkLg%3D%3D");
}
@Test
@ -50,6 +54,11 @@ class TestEncode {
var t = TemplateFactory.TXT.get("encodeJs");
t.setAttribute(TestCase.FOO, "'\"\\/");
assertThat(t.getContent()).isEqualTo("\\'\\\"\\\\\\/");
t = TemplateFactory.HTML.get("encodeJs");
t.setAttribute(TestCase.FOO, '"' + TestCase.SAMPLE_TEXT + '"');
assertThat(t.getContent()).as("with unicode")
.isEqualTo("\\u005C\\u0022\\u0054\\u0068\\u0069\\u0073\\u0020\\u0069\\u0073\\u0020\\u0061\\u0020\\u0074\\u0065\\u0073\\u0074\\u002E\\u005C\\u0022");
}
@Test
@ -57,6 +66,10 @@ class TestEncode {
var t = TemplateFactory.JSON.get("encodeJson");
t.setAttribute(TestCase.FOO, "This is a \"•test\"");
assertThat(t.getContent()).isEqualTo("{\n \"foo\": \"This is a \\\"\\u2022test\\\"\"\n}");
t = TemplateFactory.HTML.get("encodeJson");
t.setAttribute(TestCase.FOO, "\"<test>\"");
assertThat(t.getContent()).as("with html").isEqualTo("\\&quot;&lt;test&gt;\\&quot;");
}
@Test
@ -80,6 +93,11 @@ class TestEncode {
t.setAttribute(TestCase.FOO, TestCase.SAMPLE_TEXT);
assertThat(t.getContent()).isEqualTo(
"\\u0054\\u0068\\u0069\\u0073\\u0020\\u0069\\u0073\\u0020\\u0061\\u0020\\u0074\\u0065\\u0073\\u0074\\u002E");
t = TemplateFactory.HTML.get("encodeUnicode");
t.setAttribute(TestCase.FOO, '"' + TestCase.SAMPLE_TEXT + '"');
assertThat(t.getContent()).as("with js")
.contains("'\\\\u0022\\\\u0054\\\\u0068\\\\u0069\\\\u0073\\\\u0020\\\\u0069\\\\u0073\\\\u0020\\\\u0061\\\\u0020\\\\u0074\\\\u0065\\\\u0073\\\\u0074\\\\u002E\\\\u0022'");
}
@Test
@ -87,6 +105,11 @@ class TestEncode {
var t = TemplateFactory.HTML.get("encodeUrl");
t.setAttribute(TestCase.FOO, "a test &");
assertThat(t.getContent()).isEqualTo("<a href=\"https://example.com/a%20test%20%26\">a test &amp;</a>");
t = TemplateFactory.HTML.get("encodeUrlwithUnicode");
t.setAttribute(TestCase.FOO, "a=test");
assertThat(t.getContent()).as("with unicode")
.contains("https://foo.com/\\u0061\\u0025\\u0033\\u0044\\u0074\\u0065\\u0073\\u0074");
}
@Test