Skip to content

Commit bb43971

Browse files
committed
test   handling
1 parent f07e44b commit bb43971

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/test/java/org/owasp/html/HtmlSanitizerTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
import junit.framework.TestCase;
3232

33+
import java.util.Arrays;
34+
3335
import javax.annotation.Nullable;
3436

3537
import org.junit.Test;
@@ -363,7 +365,31 @@ public static final void testDuplicateAttributes() {
363365
assertEquals(
364366
sanitize("<br id=\"foo\">"),
365367
sanitize("<br id=foo id=bar>"));
368+
}
369+
370+
@Test
371+
public static final void testNbsps() {
372+
String input =
373+
"test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bob";
374+
375+
PolicyFactory policy = new HtmlPolicyBuilder()
376+
.toFactory();
377+
378+
String got = policy.sanitize(input);
379+
int[] codeUnits = new int[got.length()];
380+
for (int i = 0, n = got.length(); i < n; ++i) {
381+
codeUnits[i] = got.charAt(i);
382+
}
366383

384+
assertTrue(
385+
Arrays.toString(codeUnits),
386+
Arrays.equals(
387+
new int[] {
388+
116, 101, 115, 116,
389+
160, 160, 160, 160, 160, 160, 160, 160,
390+
98, 111, 98,
391+
},
392+
codeUnits));
367393
}
368394

369395
@Test

0 commit comments

Comments
 (0)