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

Valid email address should only start with alphanumeric #28174

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

Conversation

dek5troza
Copy link

This fixes issue #27847 where regular expression allowed email address to start with special symbols. Valid email addresses should start with alphanumeric character, and as such will be rendered as email.

Added test cases from the bug report to validate, such input will not be rendered anymore as email address.

Valid email addresses should start with alphanumeric character.
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 22, 2023
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 22, 2023
@lunny
Copy link
Member

lunny commented Nov 22, 2023

Could it start with a number?

Copy link
Member

@lng2020 lng2020 left a comment

Choose a reason for hiding this comment

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

I'm afraid it's not right. According to that issue, the correct test case should be

test(
  "?a@example.com",
  `<p>?<a href="mailto:a@example.com" rel="nofollow">a@example.com</a></p>`
)

The expected behavior of that issue is ~ not rendered but a@example.com rendered.

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Nov 23, 2023
@dek5troza
Copy link
Author

I'm afraid it's not right. According to that issue, the correct test case should be

test(
  "?a@example.com",
  `<p>?<a href="mailto:a@example.com" rel="nofollow">a@example.com</a></p>`
)

The expected behavior of that issue is ~ not rendered but a@example.com rendered.

Ok, I misunderstood the issue. I ll give it another go. Thanks

dek5troza and others added 2 commits November 23, 2023 18:59
Regular expression will attempt to match valid portion of the email
which start with ~,* or ? or their combination.
@dek5troza
Copy link
Author

Ok, so hopefully I understood the issue this time. It should handle those characters in the way you have described to me in the comment. Let me know, if I need to update anything else, and I will do it.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Nov 28, 2023

According to RFC and Golang's mail.ParseAddress: *a@b.com ~a@b.com are all valid email addresses.

Although the old regexp doesn't look good, I do not see real benefit by introducing another incorrect (hacky?) patch.


Sorry, maybe I misunderstood the PR, will do more tests.

@techknowlogick techknowlogick changed the title Valid email address should only start with alphanumeric. Valid email address should only start with alphanumeric Nov 28, 2023
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Nov 28, 2023

Made a small change (remove the ? from regexp because it doesn't affect the result, there is no ? in regexp body) and added some test cases.

dek5troza#1 (not ideal enough, see below)


Well, I am still not sure whether we should really use this patch.

Test code:

func main() {
	a, _ := mail.ParseAddress("~a@b.com")
	println(a.Address)
	a, _ = mail.ParseAddress("*a@b.com")
	println(a.Address)
}

Because ~a@a.com and *a@a.com are valid email addresses .......

@lng2020 lng2020 self-requested a review November 28, 2023 05:46
@lng2020 lng2020 added lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. and removed lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged labels Nov 28, 2023
@dek5troza
Copy link
Author

Made a small change (remove the ? from regexp because it doesn't affect the result, there is no ? in regexp body) and added some test cases.

dek5troza#1 (not ideal enough, see below)

Well, I am still not sure whether we should really use this patch.

Test code:

func main() {
	a, _ := mail.ParseAddress("~a@b.com")
	println(a.Address)
	a, _ = mail.ParseAddress("*a@b.com")
	println(a.Address)
}

Because ~a@a.com and *a@a.com are valid email addresses .......

I was just going by @lng2020 comment. Technically those are valid by RFC5322 but it's arguable how usable those are, as most email service providers would not allow them with rules and filters.

If more changes are needed with this, I ll be happy to help and update.

@dek5troza
Copy link
Author

Hey guys, do you want me to update the patch, and separate ~something as valid email, or how would you like me to proceed with this?

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Dec 8, 2023

I do not have strong objection for the "arguable" RFC format. But there are still nits:

  1. I still think it needs to "remove the ? from regexp because it doesn't affect the result, there is no ? in regexp body".
  2. It needs more tests to show the behavior, especially the edge cases like a*a and a~a if they were not covered before.
  3. It needs more comments to describe the decision and the difference from the RFC.

@dek5troza
Copy link
Author

I do not have strong objection for the "arguable" RFC format. But there are still nits:

  1. I still think it needs to "remove the ? from regexp because it doesn't affect the result, there is no ? in regexp body".
  2. It needs more tests to show the behavior, especially the edge cases like a*a and a~a if they were not covered before.
  3. It needs more comments to describe the decision and the difference from the RFC.

Cool, I ll give it till Monday, if there are more opinions, and start updating on Monday with things you have listed above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants