Skip to content

Commit 9667d5e

Browse files
committed
Add more tests for tab expansion
These show more clearly what the code is supposed to do.
1 parent f263d91 commit 9667d5e

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/test/java/com/gitblit/tests/StringUtilsTest.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,27 @@ public void testEncodeUrl() throws Exception {
6161

6262
@Test
6363
public void testEscapeForHtml() throws Exception {
64-
String input = "& < > \"";
65-
String outputNoChange = "&amp; &lt; &gt; &quot;";
66-
String outputChange = "&amp;&nbsp;&lt;&nbsp;&gt;&nbsp;&quot;";
64+
String input = "\t & < > \"";
65+
String outputNoChange = "\t &amp; &lt; &gt; &quot;";
66+
String outputChange = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;&lt;&nbsp;&gt;&nbsp;&quot;";
67+
assertEquals(outputNoChange, StringUtils.escapeForHtml(input, false));
68+
assertEquals(outputChange, StringUtils.escapeForHtml(input, true));
69+
70+
input = "a\tb";
71+
outputNoChange = "a\tb";
72+
outputChange = "a&nbsp;&nbsp;&nbsp;b";
73+
assertEquals(outputNoChange, StringUtils.escapeForHtml(input, false));
74+
assertEquals(outputChange, StringUtils.escapeForHtml(input, true));
75+
76+
input = "\ta b\t";
77+
outputNoChange = "\ta b\t";
78+
outputChange = "&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;b&nbsp;";
79+
assertEquals(outputNoChange, StringUtils.escapeForHtml(input, false));
80+
assertEquals(outputChange, StringUtils.escapeForHtml(input, true));
81+
82+
input = "\t <> \t";
83+
outputNoChange = "\t &lt;&gt; \t";
84+
outputChange = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
6785
assertEquals(outputNoChange, StringUtils.escapeForHtml(input, false));
6886
assertEquals(outputChange, StringUtils.escapeForHtml(input, true));
6987

0 commit comments

Comments
 (0)