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();