Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AYS-551 | The Email Validation Fixed. #399

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MenekseYuncu
Copy link
Contributor

Checklist

Before submitting your pull request, ensure the following:

  • Title and Branch Naming Conventions:

  • Local Testing:

    • I have tested my changes locally on Postman, and they are working as expected.
  • Code Quality:

    • The code is formatted according to the project's coding guidelines and style.
    • The code has been reviewed to ensure its quality.
    • The code does not contain any issues flagged by SonarLint.
  • Documentation:

    • Necessary documentation has been added or existing documentation has been updated, specifically detailing changes made in Postman.
  • Testing:

    • Relevant unit tests have been written and included.
    • Relevant integration tests have been written and included.
  • Reviewers and Assignees:

    • Default reviewers have been assigned to this pull request.
    • Assignees have been added if necessary.
  • Labels and Associations:

    • No specific actions are required in the Labels and Associations section for this pull request.

Comment on lines 46 to 70
if (email.startsWith(" ") || email.endsWith(" ")) {
return buildViolation(constraintValidatorContext, "email must not start or end with whitespace.");
}

if (email.chars().filter(ch -> ch == '@').count() != 1) {
return buildViolation(constraintValidatorContext, "email must contain exactly one '@' character.");
}

if (email.matches(".*[()#\\[\\]\";,\\s].*")) {
return buildViolation(constraintValidatorContext, "email contains invalid special characters.");
}

String[] parts = email.split("@", 2);
if (!Character.isLetterOrDigit(parts[0].charAt(0))) {
return buildViolation(constraintValidatorContext, "email local part must start with a letter or number.");
}

String domainPart = parts[1];
if (domainPart.startsWith("-") || domainPart.endsWith("-")) {
return buildViolation(constraintValidatorContext, "domain must not start or end with a hyphen.");
}

if (!email.matches(EMAIL_REGEX)) {
return buildViolation(constraintValidatorContext, "email is not in a valid format.");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (email.startsWith(" ") || email.endsWith(" ")) {
return buildViolation(constraintValidatorContext, "email must not start or end with whitespace.");
}
if (email.chars().filter(ch -> ch == '@').count() != 1) {
return buildViolation(constraintValidatorContext, "email must contain exactly one '@' character.");
}
if (email.matches(".*[()#\\[\\]\";,\\s].*")) {
return buildViolation(constraintValidatorContext, "email contains invalid special characters.");
}
String[] parts = email.split("@", 2);
if (!Character.isLetterOrDigit(parts[0].charAt(0))) {
return buildViolation(constraintValidatorContext, "email local part must start with a letter or number.");
}
String domainPart = parts[1];
if (domainPart.startsWith("-") || domainPart.endsWith("-")) {
return buildViolation(constraintValidatorContext, "domain must not start or end with a hyphen.");
}
if (!email.matches(EMAIL_REGEX)) {
return buildViolation(constraintValidatorContext, "email is not in a valid format.");
}
if (email.startsWith(" ") || email.endsWith(" ")) {
return this.buildViolation(constraintValidatorContext, "email must not start or end with whitespace");
}
if (email.chars().filter(ch -> ch == '@').count() != 1) {
return this.buildViolation(constraintValidatorContext, "email must contain exactly one '@' character");
}
if (email.matches(".*[()#\\[\\]\";,\\s].*")) {
return this.buildViolation(constraintValidatorContext, "email contains invalid special characters");
}
String[] parts = email.split("@", 2);
if (!Character.isLetterOrDigit(parts[0].charAt(0))) {
return this.buildViolation(constraintValidatorContext, "email local part must start with a letter or number");
}
String domainPart = parts[1];
if (domainPart.startsWith("-") || domainPart.endsWith("-")) {
return this.buildViolation(constraintValidatorContext, "domain must not start or end with a hyphen");
}
if (!email.matches(EMAIL_REGEX)) {
return this.buildViolation(constraintValidatorContext, "email is not in a valid format");
}

Comment on lines 75 to 79
private boolean buildViolation(ConstraintValidatorContext context, String message) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(message).addConstraintViolation();
return false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private boolean buildViolation(ConstraintValidatorContext context, String message) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(message).addConstraintViolation();
return false;
}
private boolean buildViolation(ConstraintValidatorContext constraintValidatorContext, String message) {
constraintValidatorContext.disableDefaultConstraintViolation();
constraintValidatorContext.buildConstraintViolationWithTemplate(message).addConstraintViolation();
return false;
}

Comment on lines +47 to +71
return this.buildViolation(constraintValidatorContext, "email must not start or end with whitespace");
}

if (email.chars().filter(ch -> ch == '@').count() != 1) {
return this.buildViolation(constraintValidatorContext, "email must contain exactly one '@' character");
}

if (email.matches(".*[()#\\[\\]\";,\\s].*")) {
return this.buildViolation(constraintValidatorContext, "email contains invalid special characters");
}


String[] parts = email.split("@", 2);
if (!Character.isLetterOrDigit(parts[0].charAt(0))) {
return this.buildViolation(constraintValidatorContext, "email local part must start with a letter or number");
}

String domainPart = parts[1];
if (domainPart.startsWith("-") || domainPart.endsWith("-")) {
return this.buildViolation(constraintValidatorContext, "domain must not start or end with a hyphen");
}

if (!email.matches(EMAIL_REGEX)) {
return this.buildViolation(constraintValidatorContext, "email is not in a valid format");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return this.buildViolation(constraintValidatorContext, "email must not start or end with whitespace");
}
if (email.chars().filter(ch -> ch == '@').count() != 1) {
return this.buildViolation(constraintValidatorContext, "email must contain exactly one '@' character");
}
if (email.matches(".*[()#\\[\\]\";,\\s].*")) {
return this.buildViolation(constraintValidatorContext, "email contains invalid special characters");
}
String[] parts = email.split("@", 2);
if (!Character.isLetterOrDigit(parts[0].charAt(0))) {
return this.buildViolation(constraintValidatorContext, "email local part must start with a letter or number");
}
String domainPart = parts[1];
if (domainPart.startsWith("-") || domainPart.endsWith("-")) {
return this.buildViolation(constraintValidatorContext, "domain must not start or end with a hyphen");
}
if (!email.matches(EMAIL_REGEX)) {
return this.buildViolation(constraintValidatorContext, "email is not in a valid format");
}
return this.buildViolation(constraintValidatorContext, "must not start or end with whitespace");
}
if (email.chars().filter(ch -> ch == '@').count() != 1) {
return this.buildViolation(constraintValidatorContext, "must contain exactly one '@' character");
}
if (email.matches(".*[()#\\[\\]\";,\\s].*")) {
return this.buildViolation(constraintValidatorContext, "contains invalid special characters");
}
String[] parts = email.split("@", 2);
if (!Character.isLetterOrDigit(parts[0].charAt(0))) {
return this.buildViolation(constraintValidatorContext, "local part must start with a letter or number");
}
String domainPart = parts[1];
if (domainPart.startsWith("-") || domainPart.endsWith("-")) {
return this.buildViolation(constraintValidatorContext, "domain must not start or end with a hyphen");
}
if (!email.matches(EMAIL_REGEX)) {
return this.buildViolation(constraintValidatorContext, "must be valid format");
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buradaki mesajların geleceğine dair testleri göremedim. Her bir mesajı ayrı ayrı böldüğümüz için bence bu senaryolar için de testler eklemeliyiz.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants