Skip to content

Commit

Permalink
Merge pull request #2243 from alphagov/PP-11355-make_regex_static_final
Browse files Browse the repository at this point in the history
PP-11355 make search service regex static final
  • Loading branch information
SandorArpa authored Nov 10, 2023
2 parents 2932220 + 19cbf7a commit 316870d
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class ServiceRequestValidator {
private static final int FIELD_MERCHANT_DETAILS_EMAIL_MAX_LENGTH = 255;
private static final int MAX_SEARCH_STRING_LENGTH = 60;

private static final Pattern ALLOWED_SEARCH_CHARS = Pattern.compile("^[0-9A-Za-z'\\-\\s]+$");

private final RequestValidations requestValidations;
private final ServiceUpdateOperationValidator serviceUpdateOperationValidator;

Expand Down Expand Up @@ -100,7 +102,6 @@ private void validateMerchantEmail(JsonNode payload) throws ValidationException
}

public Optional<Errors> validateSearchRequest(ServiceSearchRequest request) {
var allowedChars = Pattern.compile("^[0-9A-Za-z'\\-\\s]+$");
var errorList = new ArrayList<String>();
var values = request.toMap().values().stream()
.filter(value -> !isBlank(value))
Expand All @@ -113,7 +114,7 @@ public Optional<Errors> validateSearchRequest(ServiceSearchRequest request) {
if (lengthValidator(value)) {
errorList.add(SERVICE_SEARCH_LENGTH_ERR_MSG);
}
if (!allowedChars.matcher(value).matches()) {
if (!ALLOWED_SEARCH_CHARS.matcher(value).matches()) {
errorList.add(SERVICE_SEARCH_SPECIAL_CHARS_ERR_MSG);
}
});
Expand Down

0 comments on commit 316870d

Please sign in to comment.