From 9667d5ee6116d5a5041bf53eeb6c8bc62327ee61 Mon Sep 17 00:00:00 2001 From: Florian Zschocke Date: Tue, 2 Aug 2022 21:54:08 +0200 Subject: Add more tests for tab expansion These show more clearly what the code is supposed to do. --- .../java/com/gitblit/tests/StringUtilsTest.java | 24 +++++++++++++++++++--- 1 file 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 = "& < > ""; - String outputChange = "& < > ""; + String input = "\t & < > \""; + String outputNoChange = "\t & < > ""; + String outputChange = "     & < > ""; + assertEquals(outputNoChange, StringUtils.escapeForHtml(input, false)); + assertEquals(outputChange, StringUtils.escapeForHtml(input, true)); + + input = "a\tb"; + outputNoChange = "a\tb"; + outputChange = "a   b"; + assertEquals(outputNoChange, StringUtils.escapeForHtml(input, false)); + assertEquals(outputChange, StringUtils.escapeForHtml(input, true)); + + input = "\ta b\t"; + outputNoChange = "\ta b\t"; + outputChange = "    a b "; + assertEquals(outputNoChange, StringUtils.escapeForHtml(input, false)); + assertEquals(outputChange, StringUtils.escapeForHtml(input, true)); + + input = "\t <> \t"; + outputNoChange = "\t <> \t"; + outputChange = "     <>     "; assertEquals(outputNoChange, StringUtils.escapeForHtml(input, false)); assertEquals(outputChange, StringUtils.escapeForHtml(input, true)); -- cgit v1.2.3