2929package org .owasp .html ;
3030
3131import java .util .Arrays ;
32+ import java .util .Collections ;
3233import java .util .List ;
3334import java .util .Locale ;
35+ import java .util .Map ;
3436import java .util .Set ;
3537import java .util .regex .Pattern ;
3638import java .util .stream .Collectors ;
@@ -250,7 +252,31 @@ public void testSpecificStyleFilterung() {
250252 }
251253
252254 @ Test
253- public void testUnionStyleFilterung () {
255+ public void testCustomPropertyStyleFiltering () {
256+ assertEquals (
257+ Arrays .stream (new String [] {
258+ "<h1>Header</h1>" ,
259+ "<p>Paragraph 1</p>" ,
260+ "<p>Click me out</p>" ,
261+ "<p></p>" ,
262+ "<p><b>Fancy</b> with <i><b>soupy</b></i><b> tags</b>." ,
263+ "</p><p style=\" text-align:center\" >Stylish Para 1</p>" ,
264+ "<p>Stylish Para 2</p>" ,
265+ "" }).collect (Collectors .joining ("\n " )),
266+ apply (new HtmlPolicyBuilder ()
267+ .allowCommonInlineFormattingElements ()
268+ .allowCommonBlockElements ()
269+ .allowStyling (
270+ CssSchema .withProperties (
271+ Map .of ("text-align" ,
272+ new CssSchema .Property (0 ,
273+ Set .of ("center" ),
274+ Collections .emptyMap ()))))
275+ .allowStandardUrlProtocols ()));
276+ }
277+
278+ @ Test
279+ public void testUnionStyleFiltering () {
254280 assertEquals (
255281 Arrays .stream (new String [] {
256282 "<h1>Header</h1>" ,
@@ -271,6 +297,30 @@ public void testUnionStyleFilterung() {
271297 .allowStandardUrlProtocols ()));
272298 }
273299
300+ @ Test
301+ public void testCustomPropertyStyleFilteringDisallowed () {
302+ assertEquals (
303+ Arrays .stream (new String [] {
304+ "<h1>Header</h1>" ,
305+ "<p>Paragraph 1</p>" ,
306+ "<p>Click me out</p>" ,
307+ "<p></p>" ,
308+ "<p><b>Fancy</b> with <i><b>soupy</b></i><b> tags</b>." ,
309+ "</p><p>Stylish Para 1</p>" ,
310+ "<p>Stylish Para 2</p>" ,
311+ "" }).collect (Collectors .joining ("\n " )),
312+ apply (new HtmlPolicyBuilder ()
313+ .allowCommonInlineFormattingElements ()
314+ .allowCommonBlockElements ()
315+ .allowStyling (
316+ CssSchema .withProperties (
317+ Map .of ("text-align" ,
318+ new CssSchema .Property (0 ,
319+ Set .of ("left" , "right" ),
320+ Collections .emptyMap ()))))
321+ .allowStandardUrlProtocols ()));
322+ }
323+
274324 @ Test
275325 public static final void testElementTransforming () {
276326 assertEquals (
0 commit comments