Skip to content

Commit 3c86741

Browse files
cswaremikesamuel
andauthored
Add overflow-wrap to CssSchema definition list (#312)
Signed-off-by: Sven Strickroth <[email protected]> Co-authored-by: Mike Samuel <[email protected]>
1 parent c42cc40 commit 3c86741

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ Property forKey(String propertyName) {
424424
"auto", "inherit", "none");
425425
Set<String> overflowLiterals0 = Set.of(
426426
"auto", "hidden", "inherit", "scroll", "visible");
427+
Set<String> overflowWrapLiterals0 = Set.of(
428+
"normal", "break-word", "anywhere", "inherit");
427429
Set<String> overflowXLiterals0 = Set.of(
428430
"no-content", "no-display");
429431
Set<String> overflowXLiterals1 = Set.of(
@@ -668,6 +670,7 @@ Property forKey(String propertyName) {
668670
Property opacity = new Property(1, mozOpacityLiterals0, zeroFns);
669671
builder.put("opacity", opacity);
670672
builder.put("overflow", new Property(0, overflowLiterals0, zeroFns));
673+
builder.put("overflow-wrap", new Property(0, overflowWrapLiterals0, zeroFns));
671674
@SuppressWarnings("unchecked")
672675
Property overflowX = new Property(
673676
0, union(overflowXLiterals0, overflowXLiterals1), zeroFns);

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

+32
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,38 @@ public static final void testSkipAndRequireRels() {
10291029
pf.sanitize("<a href=\"http://example.com\" rel=noopener target=\"_blank\">eg</a>"));
10301030
}
10311031

1032+
@Test
1033+
public static final void testOverflowWrap() {
1034+
PolicyFactory pf = new HtmlPolicyBuilder()
1035+
.allowElements("span")
1036+
.allowStyling(CssSchema.union(CssSchema.DEFAULT, CssSchema.withProperties(List.of("overflow-wrap"))))
1037+
.toFactory();
1038+
1039+
assertEquals(
1040+
"<span style=\"overflow-wrap:anywhere\">Something</span>",
1041+
pf.sanitize("<span style=\"overflow-wrap: anywhere\">Something</span>"));
1042+
1043+
assertEquals(
1044+
"<span style=\"overflow-wrap:inherit\">Something</span>",
1045+
pf.sanitize("<span style=\"overflow-wrap: inherit\">Something</span>"));
1046+
1047+
assertEquals(
1048+
"Something",
1049+
pf.sanitize("<span style=\"overflow-wrap: something\">Something</span>"));
1050+
}
1051+
1052+
@Test
1053+
public static final void testOverflowWrapNotAllowed() {
1054+
PolicyFactory pf = new HtmlPolicyBuilder()
1055+
.allowElements("span")
1056+
.allowStyling()
1057+
.toFactory();
1058+
1059+
assertEquals(
1060+
"Something",
1061+
pf.sanitize("<span style=\"overflow-wrap: anywhere\">Something</span>"));
1062+
}
1063+
10321064
@Test
10331065
public static final void testExplicitRelsSkip() {
10341066
PolicyFactory pf = new HtmlPolicyBuilder()

0 commit comments

Comments
 (0)