From 14f84fd49ebe68918b3aa0944a6a658674a39e6b Mon Sep 17 00:00:00 2001 From: Mike Samuel Date: Mon, 18 Oct 2021 15:35:14 -0400 Subject: [PATCH] Recognize that `" + "" - + "" - + "" - + "" - + "" - + ""; + + ""; PolicyFactory pf = new HtmlPolicyBuilder() .allowElements("option", "select", "style", "svg") .allowTextIn("style") @@ -451,36 +447,49 @@ public static final void testStyleTagsInAllTheWrongPlaces() { assertEquals( "" + "" + "" - + "" + + "" + "" - + "" - + "" - + "" - + "" - + "", + + "", pf.sanitize(input) ); } @Test public static final void testSelectIsOdd() { + // Special text modes interact badly with select and option String input = ""; PolicyFactory pf = new HtmlPolicyBuilder() .allowElements("option", "select", "xmp") - .allowTextIn("xmp") + .allowTextIn("xmp", "option") .toFactory(); assertEquals( "" - + "", pf.sanitize(input) ); } + @Test + public static final void testOptionAllowsText() { + String input = ""; + PolicyFactory pf = new HtmlPolicyBuilder() + .allowElements("option", "select", "pre") + .allowTextIn("pre", "option") + .toFactory(); + assertEquals( + "" + + "", + pf.sanitize(input) + ); + } + @Test public static final void testStyleGlobally() { PolicyFactory policyBuilder = new HtmlPolicyBuilder() diff --git a/src/test/java/org/owasp/html/TagBalancingHtmlStreamRendererTest.java b/src/test/java/org/owasp/html/TagBalancingHtmlStreamRendererTest.java index 5195fde9..38a854ef 100644 --- a/src/test/java/org/owasp/html/TagBalancingHtmlStreamRendererTest.java +++ b/src/test/java/org/owasp/html/TagBalancingHtmlStreamRendererTest.java @@ -158,9 +158,9 @@ public final void testTextContent() { + "

Hello,

" + "

Hello" // Text allowed in special style tag. - + "

" + + "" // Whitespace allowed inside