HTMLFilter保留p标签

This commit is contained in:
Looly
2023-12-20 20:53:32 +08:00
parent 9e853db9ee
commit cca184257a
3 changed files with 22 additions and 1 deletions

View File

@@ -137,6 +137,7 @@ public final class HTMLFilter {
vAllowed.put("strong", no_atts);
vAllowed.put("i", no_atts);
vAllowed.put("em", no_atts);
vAllowed.put("p", no_atts);
vSelfClosingTags = new String[]{"img"};
vNeedClosingTags = new String[]{"a", "b", "strong", "i", "em"};

View File

@@ -0,0 +1,19 @@
package cn.hutool.http;
import org.junit.Assert;
import org.junit.Test;
public class HTMLFilterTest {
@Test
public void issue3433Test() {
String p1 = "<p>a</p>";
String p2 = "<p onclick=\"bbbb\">a</p>";
final HTMLFilter htmlFilter = new HTMLFilter();
String filter = htmlFilter.filter(p1);
Assert.assertEquals("<p>a</p>", filter);
filter = htmlFilter.filter(p2);
Assert.assertEquals("<p>a</p>", filter);
}
}