29
29
package org .owasp .html ;
30
30
31
31
import java .util .Arrays ;
32
+ import java .util .Collections ;
32
33
import java .util .List ;
33
34
import java .util .Locale ;
35
+ import java .util .Map ;
34
36
import java .util .Set ;
35
37
import java .util .regex .Pattern ;
36
38
import java .util .stream .Collectors ;
@@ -250,7 +252,31 @@ public void testSpecificStyleFilterung() {
250
252
}
251
253
252
254
@ 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 () {
254
280
assertEquals (
255
281
Arrays .stream (new String [] {
256
282
"<h1>Header</h1>" ,
@@ -271,6 +297,30 @@ public void testUnionStyleFilterung() {
271
297
.allowStandardUrlProtocols ()));
272
298
}
273
299
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
+
274
324
@ Test
275
325
public static final void testElementTransforming () {
276
326
assertEquals (
0 commit comments