From cf61e4ae9eaaba6aaa4bfb3fcfb33d71d96d093e Mon Sep 17 00:00:00 2001 From: Maria Martinez Date: Thu, 9 Nov 2023 12:36:37 -0800 Subject: [PATCH 1/3] fix: Aligned FE validation with BE validation --- .../java/ca/bc/gov/app/util/ClientValidationUtils.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/ca/bc/gov/app/util/ClientValidationUtils.java b/backend/src/main/java/ca/bc/gov/app/util/ClientValidationUtils.java index 081858c013..b0a089a4e2 100644 --- a/backend/src/main/java/ca/bc/gov/app/util/ClientValidationUtils.java +++ b/backend/src/main/java/ca/bc/gov/app/util/ClientValidationUtils.java @@ -4,15 +4,17 @@ import ca.bc.gov.app.dto.client.LegalTypeEnum; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.commons.lang3.EnumUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.validator.routines.EmailValidator; import org.springframework.validation.Errors; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class ClientValidationUtils { - private static final EmailValidator emailValidator = EmailValidator.getInstance(); + private static final String EMAIL_REGEX = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$"; + private static final Pattern EMAIL_PATTERN = Pattern.compile(EMAIL_REGEX); public static void validateEmail(String email, String field, Errors errors) { if (StringUtils.isBlank(email)) { @@ -20,7 +22,8 @@ public static void validateEmail(String email, String field, Errors errors) { return; } - if (!emailValidator.isValid(email)) { + Matcher emailMatcher = EMAIL_PATTERN.matcher(email); + if (!emailMatcher.matches()) { errors.rejectValue(field, "You must enter an email address in a valid format. " + "For example: name@example.com"); } From c635cb299ef4636cd4783d411e3b3c2a60c1920a Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Thu, 9 Nov 2023 12:49:57 -0800 Subject: [PATCH 2/3] chore: rearranging imports --- .../main/java/ca/bc/gov/app/util/ClientValidationUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/ca/bc/gov/app/util/ClientValidationUtils.java b/backend/src/main/java/ca/bc/gov/app/util/ClientValidationUtils.java index b0a089a4e2..b5d48570fd 100644 --- a/backend/src/main/java/ca/bc/gov/app/util/ClientValidationUtils.java +++ b/backend/src/main/java/ca/bc/gov/app/util/ClientValidationUtils.java @@ -2,10 +2,10 @@ import ca.bc.gov.app.dto.client.ClientTypeEnum; import ca.bc.gov.app.dto.client.LegalTypeEnum; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; import java.util.regex.Matcher; import java.util.regex.Pattern; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.commons.lang3.EnumUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.validation.Errors; @@ -25,7 +25,7 @@ public static void validateEmail(String email, String field, Errors errors) { Matcher emailMatcher = EMAIL_PATTERN.matcher(email); if (!emailMatcher.matches()) { errors.rejectValue(field, "You must enter an email address in a valid format. " - + "For example: name@example.com"); + + "For example: name@example.com"); } } From 868c6cf1fe17c3af74c5156a39b12ebc54629377 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Thu, 9 Nov 2023 12:51:24 -0800 Subject: [PATCH 3/3] fix: removing dependency with security issues --- backend/pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/backend/pom.xml b/backend/pom.xml index 0637d229be..e323a96730 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -92,11 +92,6 @@ org.apache.commons commons-lang3 - - commons-validator - commons-validator - 1.7 - org.apache.commons commons-text