mirror of
https://github.com/houbb/sensitive-word.git
synced 2026-03-22 08:27:36 +08:00
issue110,并废除一些黑白名单一次遍历时的冗余逻辑,并解决返回实际值时的冲突
This commit is contained in:
@@ -231,6 +231,8 @@ public class SensitiveWordContext implements IWordContext {
|
|||||||
return failFastWordPattern;
|
return failFastWordPattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public IWordContext failFastWordPattern(boolean failFastWordPattern){
|
public IWordContext failFastWordPattern(boolean failFastWordPattern){
|
||||||
this.failFastWordPattern=failFastWordPattern;
|
this.failFastWordPattern=failFastWordPattern;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -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.IWordCheck;
|
||||||
import com.github.houbb.sensitive.word.api.IWordContext;
|
import com.github.houbb.sensitive.word.api.IWordContext;
|
||||||
import com.github.houbb.sensitive.word.api.IWordData;
|
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.api.context.InnerSensitiveWordContext;
|
||||||
import com.github.houbb.sensitive.word.constant.enums.WordTypeEnum;
|
import com.github.houbb.sensitive.word.constant.enums.WordTypeEnum;
|
||||||
import com.github.houbb.sensitive.word.constant.enums.WordContainsTypeEnum;
|
import com.github.houbb.sensitive.word.constant.enums.WordContainsTypeEnum;
|
||||||
@@ -50,10 +51,12 @@ public class WordCheckWord extends AbstractWordCheck {
|
|||||||
int tempLen = 0;
|
int tempLen = 0;
|
||||||
int maxWhite = 0;
|
int maxWhite = 0;
|
||||||
int maxBlack = 0;
|
int maxBlack = 0;
|
||||||
|
int skipLen=0;
|
||||||
|
|
||||||
for (int i = beginIndex; i < rawChars.length; i++) {
|
for (int i = beginIndex; i < rawChars.length; i++) {
|
||||||
if (wordCharIgnore.ignore(i, rawChars, innerContext) && tempLen != 0) {
|
if (wordCharIgnore.ignore(i, rawChars, innerContext) && tempLen != 0) {
|
||||||
tempLen++;
|
tempLen++;
|
||||||
|
skipLen++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
char mappingChar = formatCharMapping.get(rawChars[i]);
|
char mappingChar = formatCharMapping.get(rawChars[i]);
|
||||||
@@ -91,20 +94,19 @@ public class WordCheckWord extends AbstractWordCheck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String whiteWord = txt.substring(beginIndex, beginIndex + maxWhite);
|
String string = stringBuilder.toString();
|
||||||
String blackWord = txt.substring(beginIndex, beginIndex + maxBlack);
|
String wordAllow = string.substring(0, Math.max(0,maxWhite - skipLen));
|
||||||
|
String wordDeny = string.substring(0, Math.max(0,maxBlack - skipLen));
|
||||||
String formatWhiteWord= InnerWordFormatUtils.format(whiteWord,context);
|
|
||||||
String formatBlackWord= InnerWordFormatUtils.format(blackWord,context);
|
|
||||||
|
|
||||||
|
|
||||||
return WordLengthResult.newInstance()
|
return WordLengthResult.newInstance()
|
||||||
.wordAllowLen(maxWhite)
|
.wordAllowLen(maxWhite)
|
||||||
.wordDenyLen(maxBlack)
|
.wordDenyLen(maxBlack)
|
||||||
.wordAllow(formatWhiteWord)
|
.wordAllow(wordAllow)
|
||||||
.wordDeny(formatBlackWord);
|
.wordDeny(wordDeny);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getType() {
|
protected String getType() {
|
||||||
return WordTypeEnum.WORD.getCode();
|
return WordTypeEnum.WORD.getCode();
|
||||||
|
|||||||
Reference in New Issue
Block a user