File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
owasp-java-html-sanitizer/src Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ public HtmlElementTables(
109109 LI_TAG = indexForName ("li" );
110110 SELECT_TAG = indexForName ("select" );
111111 OPTION_TAG = indexForName ("option" );
112- OPTGROUP_TAG = indexForName ("opgroup " );
112+ OPTGROUP_TAG = indexForName ("optgroup " );
113113 SCRIPT_TAG = indexForName ("script" );
114114 STYLE_TAG = indexForName ("style" );
115115 TABLE_TAG = indexForName ("table" );
Original file line number Diff line number Diff line change 1+ package org .owasp .html ;
2+
3+ import org .junit .Test ;
4+ import static org .junit .Assert .assertEquals ;
5+
6+ public class OptgroupBugTest {
7+
8+ /**
9+ * Test that optgroup elements inside select are not corrupted with extra select tags.
10+ *
11+ * Before fix: <select><optgroup><select><option></option></select></optgroup></select>
12+ * After fix: <select><optgroup><option></option></optgroup></select>
13+ */
14+ @ Test
15+ public void testOptgroupInsideSelectDoesNotAddExtraSelectTags () {
16+ PolicyFactory factory = new HtmlPolicyBuilder ()
17+ .allowElements ("select" , "optgroup" , "option" )
18+ .allowAttributes ("label" ).globally ()
19+ .toFactory ();
20+
21+ String input = "<select><optgroup label=\" mygroup\" ><option>My option</option></optgroup></select>" ;
22+ String result = factory .sanitize (input );
23+
24+ // The key assertion: no extra select tags should be inserted
25+ assertEquals (input , result );
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments