mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +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*)" +
|
regex = StrUtil.format("(?i)(\\s*{}\\s*=\\s*)" +
|
||||||
"(" +
|
"(" +
|
||||||
// name="xxxx"
|
// name="xxxx"
|
||||||
"([\"][^\"]+?[\"]\\s*)|" +
|
"([\"][^\"]+?[\"])|" +
|
||||||
// name=xxx >
|
// name=xxx > 或者 name=xxx> 或者 name=xxx name2=xxx
|
||||||
"([^>]+?\\s+(?=>))|" +
|
"([^>]+?\\s*(?=\\s|>))" +
|
||||||
// name=xxx> 或者 name=xxx name2=xxx
|
|
||||||
"([^>]+?(?=\\s|>))" +
|
|
||||||
")", attr);
|
")", attr);
|
||||||
content = content.replaceAll(regex, StrUtil.EMPTY);
|
content = content.replaceAll(regex, StrUtil.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// issue#I8YV0K 去除尾部空格
|
||||||
|
content = ReUtil.replaceAll(content, "\\s+(>|/>)", "$1");
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,4 +15,10 @@ public class IssueI8YV0KTest {
|
|||||||
final String str = "<content styleCode=\"xmChange\"/>";
|
final String str = "<content styleCode=\"xmChange\"/>";
|
||||||
Assertions.assertEquals("<content/>", HtmlUtil.removeHtmlAttr(str, "styleCode"));
|
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