release branch 0.26.2

This commit is contained in:
houbb
2025-07-05 19:27:01 +08:00
parent 32c79980e7
commit bac9a301ed
6 changed files with 55 additions and 3 deletions

View File

@@ -431,3 +431,9 @@
| 序号 | 变更类型 | 说明 | 时间 | 备注 |
|:---|:-----|-----------------------------------|:------------------|:---------------------------------------------------|
| 1 | O | 优化敏感词词库,移除多余空行、重复词。添加 xx 不是中国的敏感词 | 2025-7-5 15:58:55 | https://github.com/houbb/sensitive-word/issues/120 |
# release_0.26.2
| 序号 | 变更类型 | 说明 | 时间 | 备注 |
|:---|:-----|------------------|:------------------|:---------------------------------------------------|
| 1 | F | 修正数字等默认策略,忽略字符问题 | 2025-7-5 15:58:55 | https://github.com/houbb/sensitive-word/issues/120 |

View File

@@ -110,7 +110,7 @@ v0.24.0 开始内置支持对敏感词的分类细化,不过工作量比较大
<dependency>
<groupId>com.github.houbb</groupId>
<artifactId>sensitive-word</artifactId>
<version>0.26.1</version>
<version>0.26.2</version>
</dependency>
```

View File

@@ -6,7 +6,7 @@
<groupId>com.github.houbb</groupId>
<artifactId>sensitive-word</artifactId>
<version>0.26.1</version>
<version>0.26.2</version>
<properties>
<!--============================== All Plugins START ==============================-->

View File

@@ -10,7 +10,7 @@ ECHO "============================= RELEASE START..."
:: 版本号信息(需要手动指定)
:::: 旧版本名称
SET version=0.26.1
SET version=0.26.2
:::: 新版本名称
SET newVersion=0.27.0
:::: 组织名称

View File

@@ -1,6 +1,7 @@
package com.github.houbb.sensitive.word.support.check;
import com.github.houbb.heaven.annotation.ThreadSafe;
import com.github.houbb.sensitive.word.api.ISensitiveWordCharIgnore;
import com.github.houbb.sensitive.word.api.IWordContext;
import com.github.houbb.sensitive.word.api.context.InnerSensitiveWordContext;
import com.github.houbb.sensitive.word.support.result.WordLengthResult;
@@ -39,17 +40,31 @@ public abstract class AbstractConditionWordCheck extends AbstractWordCheck {
@Override
protected WordLengthResult getActualLength(int beginIndex, InnerSensitiveWordContext checkContext) {
// 忽略字符 https://github.com/houbb/sensitive-word/issues/118
final ISensitiveWordCharIgnore charIgnore = checkContext.wordContext().charIgnore();
final String txt = checkContext.originalText();
final char[] chars = txt.toCharArray();
final IWordContext context = checkContext.wordContext();
final Map<Character, Character> formatCharMapping = checkContext.formatCharMapping();
int actualLength = 0;
int tempIgnoreLen = 0;
// 采用 ThreadLocal 应该可以提升性能,减少对象的创建。
StringBuilder stringBuilder = new StringBuilder();
int currentIx = 0;
for(int i = beginIndex; i < txt.length(); i++) {
currentIx = i;
// 是否忽略?
boolean ignoreCharFlag = charIgnore.ignore(currentIx, chars, checkContext);
if(ignoreCharFlag) {
tempIgnoreLen++;
continue;
}
char currentChar = txt.charAt(i);
// 映射处理
char mappingChar = formatCharMapping.get(currentChar);
@@ -68,7 +83,12 @@ public abstract class AbstractConditionWordCheck extends AbstractWordCheck {
// 匹配
if(isStringCondition(currentIx, stringBuilder, checkContext)) {
actualLength = stringBuilder.length();
// 加上跳过的长度
actualLength += tempIgnoreLen;
}
// 重置
tempIgnoreLen = 0;
return WordLengthResult.newInstance()
.wordDenyLen(actualLength)

View File

@@ -0,0 +1,26 @@
package com.github.houbb.sensitive.word.bugs.b118;
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import com.github.houbb.sensitive.word.support.check.WordChecks;
import com.github.houbb.sensitive.word.support.ignore.SensitiveWordCharIgnores;
import org.junit.Assert;
import org.junit.Test;
public class Bug118Test {
@Test
public void test() {
SensitiveWordBs sensitiveWordBs = SensitiveWordBs.newInstance()
.charIgnore(SensitiveWordCharIgnores.specialChars())
.wordCheckNum(WordChecks.num())
.numCheckLen(8)
.enableNumCheck(true)
.init();
Assert.assertEquals(sensitiveWordBs.findFirst("1234567===0001哈哈哈"), "1234567===0001");
Assert.assertEquals(sensitiveWordBs.findFirst("12345670002 哈哈哈"), "12345670002");
Assert.assertEquals(sensitiveWordBs.findFirst("=====123456====70002 哈哈哈"), "=====123456====70002");
Assert.assertEquals(sensitiveWordBs.findFirst("=====123456====X70002 哈哈哈"), null);
}
}