diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bd7aa9d0..1f8226f09 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ # 🚀Changelog ------------------------------------------------------------------------------------------------------------- -# 5.8.19.M1 (2023-04-22) +# 5.8.19.M1 (2023-04-25) ### 🐣新特性 * 【db 】 优化HttpRequest.toString()内容打印(issue#3072@Github) @@ -11,6 +11,7 @@ * 【core 】 修复URLUtil.decode无法解码UTF-16问题(issue#3063@Github) * 【db 】 修复insertOrUpdate更新中条件字段没有移除问题(issue#I6W91Z@Gitee) * 【core 】 修复VIN(车架号)正则问题(pr#3078@Github) +* 【core 】 修复HtmlUtil的removeHtmlAttr方法匹配问题(issue#I6YNTF@Gitee) ------------------------------------------------------------------------------------------------------------- # 5.8.18 (2023-04-16) diff --git a/hutool-http/src/main/java/cn/hutool/http/HtmlUtil.java b/hutool-http/src/main/java/cn/hutool/http/HtmlUtil.java index 4a0fba28b..b6050d035 100755 --- a/hutool-http/src/main/java/cn/hutool/http/HtmlUtil.java +++ b/hutool-http/src/main/java/cn/hutool/http/HtmlUtil.java @@ -155,7 +155,15 @@ public class HtmlUtil { // [^>]+? 属性值,至少有一个非>的字符,>表示标签结束 // \s+(?=>) 表示属性值后跟空格加>,即末尾的属性,此时去掉空格 // (?=\s|>) 表示属性值后跟空格(属性后还有别的属性)或者跟>(最后一个属性) - regex = StrUtil.format("(?i)(\\s*{}\\s*=[^>]+?\\s+(?=>))|(\\s*{}\\s*=[^>]+?(?=\\s|>))", attr, attr); + regex = StrUtil.format("(?i)(\\s*{}\\s*=\\s*)" + + "(" + + // name="xxxx" + "([\"][^\"]+?[\"]\\s*)|" + + // name=xxx > + "([^>]+?\\s+(?=>))|" + + // name=xxx> 或者 name=xxx name2=xxx + "([^>]+?(?=\\s|>))" + + ")", attr); content = content.replaceAll(regex, StrUtil.EMPTY); } return content; diff --git a/hutool-http/src/test/java/cn/hutool/http/HtmlUtilTest.java b/hutool-http/src/test/java/cn/hutool/http/HtmlUtilTest.java index 4685bedf8..a6bd1e018 100644 --- a/hutool-http/src/test/java/cn/hutool/http/HtmlUtilTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/HtmlUtilTest.java @@ -181,4 +181,15 @@ public class HtmlUtilTest { final String result = HtmlUtil.removeAllHtmlAttr(html, "div"); Assert.assertEquals("
", result); } + + @Test + public void issueI6YNTFTest() { + String html = "