mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
修复HtmlUtil.removeHtmlAttr处理空格问题
This commit is contained in:
parent
c5a1223803
commit
40f2bcab15
@ -189,14 +189,16 @@ public class HtmlUtil {
|
||||
regex = StrUtil.format("(?i)(\\s*{}\\s*=\\s*)" +
|
||||
"(" +
|
||||
// name="xxxx"
|
||||
"([\"][^\"]+?[\"]\\s*)|" +
|
||||
// name=xxx >
|
||||
"([^>]+?\\s+(?=>))|" +
|
||||
// name=xxx> 或者 name=xxx name2=xxx
|
||||
"([^>]+?(?=\\s|>))" +
|
||||
"([\"][^\"]+?[\"])|" +
|
||||
// name=xxx > 或者 name=xxx> 或者 name=xxx name2=xxx
|
||||
"([^>]+?\\s*(?=\\s|>))" +
|
||||
")", attr);
|
||||
content = content.replaceAll(regex, StrUtil.EMPTY);
|
||||
}
|
||||
|
||||
// issue#I8YV0K 去除尾部空格
|
||||
content = ReUtil.replaceAll(content, "\\s+(>|/>)", "$1");
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
|
@ -15,4 +15,10 @@ public class IssueI8YV0KTest {
|
||||
final String str = "<content styleCode=\"xmChange\"/>";
|
||||
Assertions.assertEquals("<content/>", HtmlUtil.removeHtmlAttr(str, "styleCode"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeHtmlAttrTest3(){
|
||||
final String str = "<content styleCode=\"dada ada\" data=\"dsad\" >";
|
||||
Assertions.assertEquals("<content data=\"dsad\">", HtmlUtil.removeHtmlAttr(str, "styleCode"));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user