summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Zschocke <f.zschocke+git@gmail.com>2022-08-02 21:54:08 +0200
committerFlorian Zschocke <f.zschocke+git@gmail.com>2022-08-02 22:10:17 +0200
commit9667d5ee6116d5a5041bf53eeb6c8bc62327ee61 (patch)
treedbd86a8516f60e0afa81da69a766a08de464a17d
parentf263d91a640d408e031bec0f6a51c3b6f970c4f2 (diff)
downloadgitblit-9667d5ee6116d5a5041bf53eeb6c8bc62327ee61.tar.gz
gitblit-9667d5ee6116d5a5041bf53eeb6c8bc62327ee61.zip
Add more tests for tab expansion
These show more clearly what the code is supposed to do.
-rw-r--r--src/test/java/com/gitblit/tests/StringUtilsTest.java24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/test/java/com/gitblit/tests/StringUtilsTest.java b/src/test/java/com/gitblit/tests/StringUtilsTest.java
index b836c71f..cc579888 100644
--- a/src/test/java/com/gitblit/tests/StringUtilsTest.java
+++ b/src/test/java/com/gitblit/tests/StringUtilsTest.java
@@ -61,9 +61,27 @@ public class StringUtilsTest extends GitblitUnitTest {
@Test
public void testEscapeForHtml() throws Exception {
- String input = "& < > \"";
- String outputNoChange = "&amp; &lt; &gt; &quot;";
- String outputChange = "&amp;&nbsp;&lt;&nbsp;&gt;&nbsp;&quot;";
+ String input = "\t & < > \"";
+ String outputNoChange = "\t &amp; &lt; &gt; &quot;";
+ String outputChange = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;&lt;&nbsp;&gt;&nbsp;&quot;";
+ assertEquals(outputNoChange, StringUtils.escapeForHtml(input, false));
+ assertEquals(outputChange, StringUtils.escapeForHtml(input, true));
+
+ input = "a\tb";
+ outputNoChange = "a\tb";
+ outputChange = "a&nbsp;&nbsp;&nbsp;b";
+ assertEquals(outputNoChange, StringUtils.escapeForHtml(input, false));
+ assertEquals(outputChange, StringUtils.escapeForHtml(input, true));
+
+ input = "\ta b\t";
+ outputNoChange = "\ta b\t";
+ outputChange = "&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;b&nbsp;";
+ assertEquals(outputNoChange, StringUtils.escapeForHtml(input, false));
+ assertEquals(outputChange, StringUtils.escapeForHtml(input, true));
+
+ input = "\t <> \t";
+ outputNoChange = "\t &lt;&gt; \t";
+ outputChange = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
assertEquals(outputNoChange, StringUtils.escapeForHtml(input, false));
assertEquals(outputChange, StringUtils.escapeForHtml(input, true));