diff --git a/src/main/java/uk/gov/pay/adminusers/resources/ServiceRequestValidator.java b/src/main/java/uk/gov/pay/adminusers/resources/ServiceRequestValidator.java index e4a9e47a9..82db5b384 100644 --- a/src/main/java/uk/gov/pay/adminusers/resources/ServiceRequestValidator.java +++ b/src/main/java/uk/gov/pay/adminusers/resources/ServiceRequestValidator.java @@ -100,7 +100,7 @@ private void validateMerchantEmail(JsonNode payload) throws ValidationException } public Optional validateSearchRequest(ServiceSearchRequest request) { - var allowedChars = Pattern.compile("^[0-9A-Za-z\\s]+$"); + var allowedChars = Pattern.compile("^[0-9A-Za-z'\\-\\s]+$"); var errorList = new ArrayList(); var values = request.toMap().values().stream() .filter(value -> !isBlank(value)) diff --git a/src/test/java/uk/gov/pay/adminusers/resources/ServiceRequestValidatorTest.java b/src/test/java/uk/gov/pay/adminusers/resources/ServiceRequestValidatorTest.java index ebdbce49c..1ce903a76 100644 --- a/src/test/java/uk/gov/pay/adminusers/resources/ServiceRequestValidatorTest.java +++ b/src/test/java/uk/gov/pay/adminusers/resources/ServiceRequestValidatorTest.java @@ -123,6 +123,13 @@ public void shouldAllowWellFormedRequest_whenSearchingServices() throws JsonProc assertThat(errors.isPresent(), is(false)); } + @Test + public void shouldAllowWellFormedRequest_whenSearchingServicesWithApostropheAndHyphen() throws JsonProcessingException { + var searchRequest = ServiceSearchRequest.from(mapper.readTree("{\"service_name\": \"test's test-name\"}")); + Optional errors = serviceRequestValidator.validateSearchRequest(searchRequest); + assertThat(errors.isPresent(), is(false)); + } + @Test public void shouldErrorIfSpecialCharsArePresent_whenSearchingServices() throws JsonProcessingException { var searchRequest = ServiceSearchRequest.from(mapper.readTree("{\"service_name\": \"!@£\"}"));