Skip to content

Commit

Permalink
Merge pull request #2241 from alphagov/PP-11355-allow_apostrophe
Browse files Browse the repository at this point in the history
PP-11355 allow apostrophes and hyphens when searching by service name
  • Loading branch information
SandorArpa authored Nov 10, 2023
2 parents a078aa3 + 4e9cb86 commit 2932220
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void validateMerchantEmail(JsonNode payload) throws ValidationException
}

public Optional<Errors> 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<String>();
var values = request.toMap().values().stream()
.filter(value -> !isBlank(value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> errors = serviceRequestValidator.validateSearchRequest(searchRequest);
assertThat(errors.isPresent(), is(false));
}

@Test
public void shouldErrorIfSpecialCharsArePresent_whenSearchingServices() throws JsonProcessingException {
var searchRequest = ServiceSearchRequest.from(mapper.readTree("{\"service_name\": \"!@£\"}"));
Expand Down

0 comments on commit 2932220

Please sign in to comment.