Skip to content

Commit e283825

Browse files
Allows start, end, justify-all and match-parent as text-align values.
After this change, all values currently listed on MDN for text-align are allowed: https://developer.mozilla.org/en-US/docs/Web/CSS/text-align#values
1 parent f729a08 commit e283825

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ Property forKey(String propertyName) {
452452
Set<String> tableLayoutLiterals0 = j8().setOf(
453453
"auto", "fixed", "inherit");
454454
Set<String> textAlignLiterals0 = j8().setOf(
455-
"center", "inherit", "justify");
455+
"center", "end", "inherit", "justify", "justify-all", "match-parent", "start");
456456
Set<String> textDecorationLiterals0 = j8().setOf(
457457
"blink", "line-through", "overline", "underline");
458458
Set<String> textTransformLiterals0 = j8().setOf(

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

+17
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,23 @@ public final void testHtmlPolicyBuilderDefinitionWithNoAttributesDefinedGlobally
12941294
new HtmlPolicyBuilder().allowElements().allowAttributes().globally().toFactory();
12951295
}
12961296

1297+
@Test
1298+
public final void testCSSTextAlign() {
1299+
HtmlPolicyBuilder builder = new HtmlPolicyBuilder();
1300+
PolicyFactory factory = builder.allowElements("span")
1301+
.allowAttributes("style").onElements("span").allowStyling()
1302+
.toFactory();
1303+
1304+
String toSanitizeTextAlignStart = "<span style=\"text-align:start\">start</span>";
1305+
assertEquals(toSanitizeTextAlignStart, factory.sanitize(toSanitizeTextAlignStart));
1306+
1307+
String toSanitizeTextAlignEnd = "<span style=\"text-align:end\">end</span>";
1308+
assertEquals(toSanitizeTextAlignEnd, factory.sanitize(toSanitizeTextAlignEnd));
1309+
1310+
String toSanitizeTextAlignFoo = "<span style=\"text-align:foo\">foo</span>";
1311+
assertEquals("foo", factory.sanitize(toSanitizeTextAlignFoo));
1312+
}
1313+
12971314
@Test
12981315
public final void testCSSFontSize() {
12991316
HtmlPolicyBuilder builder = new HtmlPolicyBuilder();

0 commit comments

Comments
 (0)