From 5b315becb7b09075693b2145902f3a29d16edf2d Mon Sep 17 00:00:00 2001 From: Sandor Arpa Date: Fri, 10 Nov 2023 15:54:23 +0000 Subject: [PATCH] PP-11355 add real apostrophe to regex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow both ' and ’ - update regex to allow real apostrophe. --- .../gov/pay/adminusers/resources/ServiceRequestValidator.java | 4 ++-- .../pay/adminusers/resources/ServiceRequestValidatorTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 be0422038..14acf99b0 100644 --- a/src/main/java/uk/gov/pay/adminusers/resources/ServiceRequestValidator.java +++ b/src/main/java/uk/gov/pay/adminusers/resources/ServiceRequestValidator.java @@ -26,13 +26,13 @@ public class ServiceRequestValidator { public static final String SERVICE_SEARCH_SUPPORT_ERR_MSG = "Search only supports searching by service name or merchant name"; public static final String SERVICE_SEARCH_LENGTH_ERR_MSG = "Search strings can only be 60 characters or less"; - public static final String SERVICE_SEARCH_SPECIAL_CHARS_ERR_MSG = "Search strings can only contain letters, numbers and spaces"; + public static final String SERVICE_SEARCH_SPECIAL_CHARS_ERR_MSG = "Search strings can only contain letters, numbers, spaces, apostrophes and hyphens"; private static final int FIELD_MERCHANT_DETAILS_NAME_MAX_LENGTH = 255; 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 static final Pattern ALLOWED_SEARCH_CHARS = Pattern.compile("^[0-9A-Za-z'’\\-\\s]+$"); private final RequestValidations requestValidations; private final ServiceUpdateOperationValidator serviceUpdateOperationValidator; 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 1ce903a76..7c004bff8 100644 --- a/src/test/java/uk/gov/pay/adminusers/resources/ServiceRequestValidatorTest.java +++ b/src/test/java/uk/gov/pay/adminusers/resources/ServiceRequestValidatorTest.java @@ -125,7 +125,7 @@ public void shouldAllowWellFormedRequest_whenSearchingServices() throws JsonProc @Test public void shouldAllowWellFormedRequest_whenSearchingServicesWithApostropheAndHyphen() throws JsonProcessingException { - var searchRequest = ServiceSearchRequest.from(mapper.readTree("{\"service_name\": \"test's test-name\"}")); + var searchRequest = ServiceSearchRequest.from(mapper.readTree("{\"service_name\": \"King’s Academy - 2\"}")); Optional errors = serviceRequestValidator.validateSearchRequest(searchRequest); assertThat(errors.isPresent(), is(false)); }