Skip to content

Commit 66794b6

Browse files
committed
Fix table formatting
This pulls PR #186 locally and moves the unittest to a different file. I believe this addresses issue #137
1 parent 8d85dc5 commit 66794b6

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/main/java/org/owasp/html/HtmlElementTables.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ public HtmlElementTables(
142142
TD_TAG, new int[] { TR_TAG, TD_TAG, TH_TAG },
143143
new int[] { TABLE_TAG, TBODY_TAG, TR_TAG }),
144144
new FreeWrapper(
145-
TH_TAG, new int[] { TR_TAG, TD_TAG, TR_TAG },
145+
TH_TAG, new int[] { TR_TAG, TD_TAG, TH_TAG },
146146
new int[] { TABLE_TAG, TBODY_TAG, TR_TAG }),
147147
new FreeWrapper(
148-
TR_TAG, new int[] { TBODY_TAG, THEAD_TAG, TFOOT_TAG, TR_TAG },
148+
TR_TAG, new int[] { TBODY_TAG, THEAD_TAG, TFOOT_TAG, TR_TAG, TD_TAG, TH_TAG },
149149
new int[] { TABLE_TAG, TBODY_TAG }),
150150
new FreeWrapper(
151151
TBODY_TAG, new int[] { TABLE_TAG, THEAD_TAG, TBODY_TAG, TFOOT_TAG },

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

+17
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,23 @@ public static final void testNoscriptInAttribute() {
958958
"<noscript><p title=\"</noscript><img src=x onerror=alert(1)>\">"));
959959
}
960960

961+
@Test
962+
public static final void testTableStructure() {
963+
String input =
964+
"<TABLE>"
965+
+ "<TR><TD>Foo<TD>Bar"
966+
+ "<TR><TH>Baz<TH>Boo<TH>Far<TH>Faz"
967+
+ "<TR><TD>Oink<TD>Doink<TD>Poink<TD>Toink";
968+
String sanitized = Sanitizers.TABLES.sanitize(input);
969+
assertEquals(
970+
("<table><tbody>"
971+
+ "<tr><td>Foo</td><td>Bar</td></tr>"
972+
+ "<tr><th>Baz</th><th>Boo</th><th>Far</th><th>Faz</th></tr>"
973+
+ "<tr><td>Oink</td><td>Doink</td><td>Poink</td><td>Toink</td></tr>"
974+
+ "</tbody></table>"),
975+
sanitized);
976+
}
977+
961978
private static String apply(HtmlPolicyBuilder b) {
962979
return apply(b, EXAMPLE);
963980
}

0 commit comments

Comments
 (0)