diff --git a/CHANGE_LOG.md b/CHANGE_LOG.md
index 1e668ba..e738098 100644
--- a/CHANGE_LOG.md
+++ b/CHANGE_LOG.md
@@ -324,3 +324,9 @@
| 序号 | 变更类型 | 说明 | 时间 | 备注 |
|:---|:-----|---------|:------------------|:------|
| 1 | A | IPV4 校验 | 2024-6-01 15:02:25 | https://github.com/houbb/sensitive-word/issues/43 |
+
+# release_0.18.0
+
+| 序号 | 变更类型 | 说明 | 时间 | 备注 |
+|:---|:-----|-------------------------|:-------------------|:-----|
+| 1 | A | 优化网址匹配策略,避免命中 1.jpg 之类的 | 2024-7-07 15:02:25 | |
diff --git a/README.md b/README.md
index 97700fe..10030c1 100644
--- a/README.md
+++ b/README.md
@@ -52,15 +52,14 @@
[CHANGE_LOG.md](https://github.com/houbb/sensitive-word/blob/master/CHANGE_LOG.md)
-### V0.16.2:
-
-- 移除部分敏感词
-- 默认关闭 url/email/num 的校验
-
### V0.17.0
- 支持 ipv4
+### V0.18.0
+
+- 优化 URL 检测,降低误判率
+
## 更多资料
### 敏感词控台
@@ -91,7 +90,7 @@
com.github.houbb
sensitive-word
- 0.17.0
+ 0.18.0
```
@@ -393,15 +392,14 @@ Assert.assertEquals("[]", wordList2.toString());
用于过滤常见的网址信息,默认未启用。
-```java
-final String text = "点击链接 www.baidu.com查看答案";
-final SensitiveWordBs sensitiveWordBs = SensitiveWordBs.newInstance().enableUrlCheck(true).init();
-
- '
-List wordList = sensitiveWordBs.findAll(text);
-Assert.assertEquals("[www.baidu.com]", wordList.toString());
+v0.18.0 优化 URL 检测,更加严格,降低误判率
-Assert.assertEquals("点击链接 *************查看答案", sensitiveWordBs.replace(text));
+```java
+final String text = "点击链接 https://www.baidu.com 查看答案";
+final SensitiveWordBs sensitiveWordBs = SensitiveWordBs.newInstance().enableUrlCheck(true).init();
+List wordList = sensitiveWordBs.findAll(text);
+Assert.assertEquals("[https://www.baidu.com]", wordList.toString());
+Assert.assertEquals("点击链接 ********************* 查看答案", sensitiveWordBs.replace(text));
```
### IPV4 检测
diff --git a/pom.xml b/pom.xml
index 76470d9..868a9c1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.github.houbb
sensitive-word
- 0.17.0
+ 0.18.0
@@ -25,7 +25,7 @@
1.7
- 0.10.0
+ 0.11.0
1.8.1
diff --git a/release.bat b/release.bat
index eb89986..d4a3549 100644
--- a/release.bat
+++ b/release.bat
@@ -10,9 +10,9 @@ ECHO "============================= RELEASE START..."
:: 版本号信息(需要手动指定)
:::: 旧版本名称
-SET version=0.17.0
+SET version=0.18.0
:::: 新版本名称
-SET newVersion=0.18.0
+SET newVersion=0.19.0
:::: 组织名称
SET groupName=com.github.houbb
:::: 项目名称
diff --git a/src/main/java/com/github/houbb/sensitive/word/support/check/WordCheckUrl.java b/src/main/java/com/github/houbb/sensitive/word/support/check/WordCheckUrl.java
index 6e797c9..4ca748b 100644
--- a/src/main/java/com/github/houbb/sensitive/word/support/check/WordCheckUrl.java
+++ b/src/main/java/com/github/houbb/sensitive/word/support/check/WordCheckUrl.java
@@ -44,7 +44,7 @@ public class WordCheckUrl extends AbstractConditionWordCheck {
@Override
protected boolean isCharCondition(char mappingChar, int index, InnerSensitiveWordContext checkContext) {
- return CharUtil.isWebSiteChar(mappingChar);
+ return CharUtil.isWebSiteChar(mappingChar) || mappingChar == ':' || mappingChar == '/';
}
@Override
@@ -58,8 +58,9 @@ public class WordCheckUrl extends AbstractConditionWordCheck {
return false;
}
+ // 改为 http:// 或者 https:// 开头
String string = stringBuilder.toString();
- return RegexUtil.isWebSite(string);
+ return RegexUtil.isUrl(string);
}
}
diff --git a/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsUrlTest.java b/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsUrlTest.java
index 38aae98..0124a03 100644
--- a/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsUrlTest.java
+++ b/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsUrlTest.java
@@ -20,13 +20,13 @@ public class SensitiveWordBsUrlTest {
*/
@Test
public void commonUrlTest() {
- final String text = "点击链接 www.baidu.com查看答案";
+ final String text = "点击链接 https://www.baidu.com 查看答案";
final SensitiveWordBs sensitiveWordBs = SensitiveWordBs.newInstance().enableUrlCheck(true).init();
List wordList = sensitiveWordBs.findAll(text);
- Assert.assertEquals("[www.baidu.com]", wordList.toString());
+ Assert.assertEquals("[https://www.baidu.com]", wordList.toString());
- Assert.assertEquals("点击链接 *************查看答案", sensitiveWordBs.replace(text));
+ Assert.assertEquals("点击链接 ********************* 查看答案", sensitiveWordBs.replace(text));
}
/**
@@ -39,15 +39,15 @@ public class SensitiveWordBsUrlTest {
*/
@Test
public void imageUrlTest() {
- final String text = "双击查看大图 www.big-image.png查看";
+ final String text = "双击查看大图 http://www.big-image.png 查看";
final SensitiveWordBs sensitiveWordBs = SensitiveWordBs.newInstance()
.enableUrlCheck(true)
.init();
List wordList = sensitiveWordBs.findAll(text);
- Assert.assertEquals("[www.big-image.png]", wordList.toString());
+ Assert.assertEquals("[http://www.big-image.png]", wordList.toString());
- Assert.assertEquals("双击查看大图 *****************查看", sensitiveWordBs.replace(text));
+ Assert.assertEquals("双击查看大图 ************************ 查看", sensitiveWordBs.replace(text));
}
}