diff --git a/hutool-http/src/main/java/org/dromara/hutool/http/html/HTMLFilter.java b/hutool-http/src/main/java/org/dromara/hutool/http/html/HTMLFilter.java index 3061f55fc..3af740f26 100644 --- a/hutool-http/src/main/java/org/dromara/hutool/http/html/HTMLFilter.java +++ b/hutool-http/src/main/java/org/dromara/hutool/http/html/HTMLFilter.java @@ -149,6 +149,8 @@ public final class HTMLFilter { vAllowed.put("strong", no_atts); vAllowed.put("i", no_atts); vAllowed.put("em", no_atts); + // issue#3433 + vAllowed.put("p", no_atts); vSelfClosingTags = new String[]{"img"}; vNeedClosingTags = new String[]{"a", "b", "strong", "i", "em"}; @@ -429,7 +431,7 @@ public final class HTMLFilter { ending = ""; } - if (ending == null || ending.length() < 1) { + if (ending == null || ending.isEmpty()) { if (vTagCounts.containsKey(name)) { vTagCounts.put(name, vTagCounts.get(name) + 1); } else { diff --git a/hutool-http/src/test/java/org/dromara/hutool/http/html/HTMLFilterTest.java b/hutool-http/src/test/java/org/dromara/hutool/http/html/HTMLFilterTest.java new file mode 100644 index 000000000..8eb026f3a --- /dev/null +++ b/hutool-http/src/test/java/org/dromara/hutool/http/html/HTMLFilterTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023. looly(loolly@aliyun.com) + * Hutool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * https://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +package org.dromara.hutool.http.html; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class HTMLFilterTest { + @Test + void issue3433Test() { + final String p1 = "
a
"; + final String p2 = "a
"; + + final HTMLFilter htmlFilter = new HTMLFilter(); + String filter = htmlFilter.filter(p1); + Assertions.assertEquals("a
", filter); + + filter = htmlFilter.filter(p2); + Assertions.assertEquals("a
", filter); + } +}