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

Added is_valid_email_address.rs #783

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

Conversation

lyqio
Copy link

@lyqio lyqio commented Aug 26, 2024

Changes

  • add is_valid_email_address.rs

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I ran bellow commands using the latest version of rust nightly.
  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked COUNTRIBUTING.md and my code follows its guidelines.

@codecov-commenter
Copy link

codecov-commenter commented Aug 26, 2024

Codecov Report

Attention: Patch coverage is 96.95122% with 5 lines in your changes missing coverage. Please review.

Project coverage is 95.34%. Comparing base (b2acfd2) to head (5460340).
Report is 14 commits behind head on master.

Files with missing lines Patch % Lines
src/string/is_valid_email_address.rs 96.95% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #783      +/-   ##
==========================================
+ Coverage   95.33%   95.34%   +0.01%     
==========================================
  Files         310      311       +1     
  Lines       22657    22821     +164     
==========================================
+ Hits        21600    21759     +159     
- Misses       1057     1062       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@vil02 vil02 left a comment

Choose a reason for hiding this comment

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

The definition of the valid email address is slightly more involved, cf. https://en.wikipedia.org/wiki/Email_address#Examples
in particular, "john..doe"@example.org is perfectly fine.

This can be merged only if all of the edge cases are covered.

Copy link
Author

@lyqio lyqio left a comment

Choose a reason for hiding this comment

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

I rewrote some of the code and now passes all of the tests on https://en.wikipedia.org/wiki/Email_address#Examples

src/string/is_valid_email_address.rs Outdated Show resolved Hide resolved
src/string/is_valid_email_address.rs Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Please make sure that tests cover all of the lines.

@lyqio
Copy link
Author

lyqio commented Sep 8, 2024

I handled all the things that you requested.

src/string/is_valid_email_address.rs Outdated Show resolved Hide resolved
src/string/is_valid_email_address.rs Outdated Show resolved Hide resolved
@vil02
Copy link
Member

vil02 commented Sep 13, 2024

Please make sure to update your branch (cf. #789) - otherwise the CI will fail.

@lyqio lyqio force-pushed the email-address branch 2 times, most recently from 0c45ece to 2d4da60 Compare September 14, 2024 11:15
@lyqio
Copy link
Author

lyqio commented Sep 14, 2024

I think I fixed all the issues and made the IP checking better.

src/string/is_valid_email_address.rs Outdated Show resolved Hide resolved
Copy link
Member

@vil02 vil02 left a comment

Choose a reason for hiding this comment

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

Please consider using more consistent naming: sometime the valid part is in the middle and sometimes at the end. Perhaps it is not needed at all?

src/string/is_valid_email_address.rs Outdated Show resolved Hide resolved
src/string/is_valid_email_address.rs Outdated Show resolved Hide resolved
@lyqio lyqio force-pushed the email-address branch 2 times, most recently from 05040a6 to 88d09e3 Compare September 19, 2024 21:15
Comment on lines +110 to +128
fn is_valid_local_part(local_part: &str) -> bool {
if local_part.len() > MAX_LOCAL_PART_LENGTH as usize {
return false;
}

if !is_valid_quotes(local_part) {
return false;
}

if !contains_legal_local_characters(local_part) {
return false;
}

if has_bad_dots(local_part) {
return false;
}

true
}
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about having a similar approach as in is_valid_domain? I.e. if the local_part starts and ends ". then a function is_valid_local_quoted_part and is_valid_local_unquoted_part?

Copy link
Author

Choose a reason for hiding this comment

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

I don't think this would work as not all email addresses are made up of only a single string, for example a."b".c is valid although it does not begin and end with quotes. In addition due to the fact that the contents of all strings are removed at the start of the local part checking, I believe that it would make the code less readable.

Copy link
Member

Choose a reason for hiding this comment

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

a."b".c is unquoted. It contains a " character, therefore it is not valid (cf. wiki).

Copy link

github-actions bot commented Nov 4, 2024

This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants