RED-3761 prevent compiledPrefixPattern to be nullable by testing prefixPattern parameter
This commit is contained in:
parent
7963c57552
commit
0014d7725a
@ -261,27 +261,31 @@ public class Section {
|
||||
@Argument(ArgumentType.BOOLEAN) boolean patternCaseInsensitive, @Argument(ArgumentType.INTEGER) int group,
|
||||
@Argument(ArgumentType.REGEX) String valuePattern) {
|
||||
|
||||
Pattern compiledValuePattern = valuePattern == null ? null : Patterns.getCompiledPattern(valuePattern, patternCaseInsensitive);
|
||||
Pattern compiledPrefixPattern = prefixPattern == null ? null : Patterns.getCompiledPattern(prefixPattern, patternCaseInsensitive);
|
||||
if (StringUtils.isEmpty(prefixPattern)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var compiledValuePattern = valuePattern == null ? null : Patterns.getCompiledPattern(valuePattern, patternCaseInsensitive);
|
||||
var compiledPrefixPattern = Patterns.getCompiledPattern(prefixPattern, patternCaseInsensitive);
|
||||
|
||||
Set<Entity> expanded = new HashSet<>();
|
||||
for (Entity entity : entities) {
|
||||
for (var entity : entities) {
|
||||
|
||||
if (!entity.getType().equals(type) || entity.getTextBefore() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (valuePattern != null) {
|
||||
Matcher valueMatcher = compiledValuePattern.matcher(entity.getWord());
|
||||
var valueMatcher = compiledValuePattern.matcher(entity.getWord());
|
||||
if (!valueMatcher.matches()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Matcher matcher = compiledPrefixPattern.matcher(entity.getTextBefore());
|
||||
var matcher = compiledPrefixPattern.matcher(entity.getTextBefore());
|
||||
|
||||
while (matcher.find()) {
|
||||
String match = matcher.group(group);
|
||||
var match = matcher.group(group);
|
||||
|
||||
if (StringUtils.isNotBlank(match)) {
|
||||
|
||||
@ -290,7 +294,7 @@ public class Section {
|
||||
continue;
|
||||
}
|
||||
|
||||
Set<Entity> expandedEntities = findEntities(match + entity.getWord(), type, false, entity.isRedaction(), entity.getMatchedRule(), entity.getRedactionReason(), entity.getLegalBasis(), Engine.RULE, false);
|
||||
var expandedEntities = findEntities(match + entity.getWord(), type, false, entity.isRedaction(), entity.getMatchedRule(), entity.getRedactionReason(), entity.getLegalBasis(), Engine.RULE, false);
|
||||
expanded.addAll(EntitySearchUtils.findNonOverlappingMatchEntities(entities, expandedEntities));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user