From 91e811b360c780f90462c8f826ffc241bbfe06a5 Mon Sep 17 00:00:00 2001 From: yds <11232266+yuds11@user.noreply.gitee.com> Date: Fri, 2 May 2025 22:49:43 +0800 Subject: [PATCH] =?UTF-8?q?issue110,=E5=B9=B6=E5=BA=9F=E9=99=A4=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E9=BB=91=E7=99=BD=E5=90=8D=E5=8D=95=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E9=81=8D=E5=8E=86=E6=97=B6=E7=9A=84=E5=86=97=E4=BD=99=E9=80=BB?= =?UTF-8?q?=E8=BE=91,=E5=B9=B6=E8=A7=A3=E5=86=B3=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=AE=9E=E9=99=85=E5=80=BC=E6=97=B6=E7=9A=84=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sensitive/word/bs/SensitiveWordContext.java | 2 ++ .../word/support/check/WordCheckWord.java | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/github/houbb/sensitive/word/bs/SensitiveWordContext.java b/src/main/java/com/github/houbb/sensitive/word/bs/SensitiveWordContext.java index e2a68c8..6f142fd 100644 --- a/src/main/java/com/github/houbb/sensitive/word/bs/SensitiveWordContext.java +++ b/src/main/java/com/github/houbb/sensitive/word/bs/SensitiveWordContext.java @@ -231,6 +231,8 @@ public class SensitiveWordContext implements IWordContext { return failFastWordPattern; } + + @Override public IWordContext failFastWordPattern(boolean failFastWordPattern){ this.failFastWordPattern=failFastWordPattern; return this; diff --git a/src/main/java/com/github/houbb/sensitive/word/support/check/WordCheckWord.java b/src/main/java/com/github/houbb/sensitive/word/support/check/WordCheckWord.java index a72abd6..f7779d1 100644 --- a/src/main/java/com/github/houbb/sensitive/word/support/check/WordCheckWord.java +++ b/src/main/java/com/github/houbb/sensitive/word/support/check/WordCheckWord.java @@ -5,6 +5,7 @@ import com.github.houbb.sensitive.word.api.ISensitiveWordCharIgnore; import com.github.houbb.sensitive.word.api.IWordCheck; import com.github.houbb.sensitive.word.api.IWordContext; import com.github.houbb.sensitive.word.api.IWordData; +import com.github.houbb.sensitive.word.api.IWordFormat; import com.github.houbb.sensitive.word.api.context.InnerSensitiveWordContext; import com.github.houbb.sensitive.word.constant.enums.WordTypeEnum; import com.github.houbb.sensitive.word.constant.enums.WordContainsTypeEnum; @@ -50,10 +51,12 @@ public class WordCheckWord extends AbstractWordCheck { int tempLen = 0; int maxWhite = 0; int maxBlack = 0; + int skipLen=0; for (int i = beginIndex; i < rawChars.length; i++) { if (wordCharIgnore.ignore(i, rawChars, innerContext) && tempLen != 0) { tempLen++; + skipLen++; continue; } char mappingChar = formatCharMapping.get(rawChars[i]); @@ -91,20 +94,19 @@ public class WordCheckWord extends AbstractWordCheck { } } - String whiteWord = txt.substring(beginIndex, beginIndex + maxWhite); - String blackWord = txt.substring(beginIndex, beginIndex + maxBlack); - - String formatWhiteWord= InnerWordFormatUtils.format(whiteWord,context); - String formatBlackWord= InnerWordFormatUtils.format(blackWord,context); + String string = stringBuilder.toString(); + String wordAllow = string.substring(0, Math.max(0,maxWhite - skipLen)); + String wordDeny = string.substring(0, Math.max(0,maxBlack - skipLen)); return WordLengthResult.newInstance() .wordAllowLen(maxWhite) .wordDenyLen(maxBlack) - .wordAllow(formatWhiteWord) - .wordDeny(formatBlackWord); + .wordAllow(wordAllow) + .wordDeny(wordDeny); } + @Override protected String getType() { return WordTypeEnum.WORD.getCode();