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.BOOLEAN) boolean patternCaseInsensitive, @Argument(ArgumentType.INTEGER) int group,
|
||||||
@Argument(ArgumentType.REGEX) String valuePattern) {
|
@Argument(ArgumentType.REGEX) String valuePattern) {
|
||||||
|
|
||||||
Pattern compiledValuePattern = valuePattern == null ? null : Patterns.getCompiledPattern(valuePattern, patternCaseInsensitive);
|
if (StringUtils.isEmpty(prefixPattern)) {
|
||||||
Pattern compiledPrefixPattern = prefixPattern == null ? null : Patterns.getCompiledPattern(prefixPattern, patternCaseInsensitive);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var compiledValuePattern = valuePattern == null ? null : Patterns.getCompiledPattern(valuePattern, patternCaseInsensitive);
|
||||||
|
var compiledPrefixPattern = Patterns.getCompiledPattern(prefixPattern, patternCaseInsensitive);
|
||||||
|
|
||||||
Set<Entity> expanded = new HashSet<>();
|
Set<Entity> expanded = new HashSet<>();
|
||||||
for (Entity entity : entities) {
|
for (var entity : entities) {
|
||||||
|
|
||||||
if (!entity.getType().equals(type) || entity.getTextBefore() == null) {
|
if (!entity.getType().equals(type) || entity.getTextBefore() == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valuePattern != null) {
|
if (valuePattern != null) {
|
||||||
Matcher valueMatcher = compiledValuePattern.matcher(entity.getWord());
|
var valueMatcher = compiledValuePattern.matcher(entity.getWord());
|
||||||
if (!valueMatcher.matches()) {
|
if (!valueMatcher.matches()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher matcher = compiledPrefixPattern.matcher(entity.getTextBefore());
|
var matcher = compiledPrefixPattern.matcher(entity.getTextBefore());
|
||||||
|
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String match = matcher.group(group);
|
var match = matcher.group(group);
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(match)) {
|
if (StringUtils.isNotBlank(match)) {
|
||||||
|
|
||||||
@ -290,7 +294,7 @@ public class Section {
|
|||||||
continue;
|
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));
|
expanded.addAll(EntitySearchUtils.findNonOverlappingMatchEntities(entities, expandedEntities));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user