Skip to content

Commit

Permalink
Add more tests for tab expansion
Browse files Browse the repository at this point in the history
These show more clearly what the code is supposed to do.
  • Loading branch information
flaix committed Aug 2, 2022
1 parent f263d91 commit 9667d5e
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/test/java/com/gitblit/tests/StringUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,27 @@ public void testEncodeUrl() throws Exception {

@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));

Expand Down

0 comments on commit 9667d5e

Please sign in to comment.