@@ -61,11 +61,39 @@ public void testEncodeUrl() throws Exception {
6161
6262 @ Test
6363 public void testEscapeForHtml () throws Exception {
64- String input = "& < > \" \t " ;
65- String outputNoChange = "& < > " \t " ;
66- String outputChange = "& ; < ; >& nbsp;" ;   ;   ; " ;
64+ String input = "\t & < > \" " ;
65+ String outputNoChange = "\t & < > "" ;
66+ String outputChange = "  ;   ; & ; < ; > ; " ;" ;
6767 assertEquals (outputNoChange , StringUtils .escapeForHtml (input , false ));
6868 assertEquals (outputChange , StringUtils .escapeForHtml (input , true ));
69+
70+ input = "a\t b" ;
71+ outputNoChange = "a\t b" ;
72+ outputChange = "a b" ;
73+ assertEquals (outputNoChange , StringUtils .escapeForHtml (input , false ));
74+ assertEquals (outputChange , StringUtils .escapeForHtml (input , true ));
75+
76+ input = "\t a b\t " ;
77+ outputNoChange = "\t a b\t " ;
78+ outputChange = " a b " ;
79+ assertEquals (outputNoChange , StringUtils .escapeForHtml (input , false ));
80+ assertEquals (outputChange , StringUtils .escapeForHtml (input , true ));
81+
82+ input = "\t <> \t " ;
83+ outputNoChange = "\t <> \t " ;
84+ outputChange = " <> " ;
85+ assertEquals (outputNoChange , StringUtils .escapeForHtml (input , false ));
86+ assertEquals (outputChange , StringUtils .escapeForHtml (input , true ));
87+
88+ String tabs = "\t " ;
89+ int tabSpaces ;
90+ int expectedLength ;
91+ for (int i = 0 ; i < 50 ; i ++) {
92+ tabSpaces = 4 - i % 4 ;
93+ expectedLength = (i + tabSpaces ) * 6 ; // = 6 chars
94+ assertEquals (expectedLength , StringUtils .escapeForHtml (tabs , true ).length ());
95+ tabs = " " + tabs ;
96+ }
6997 }
7098
7199 @ Test
0 commit comments