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

MF-798 - Add utf8 support for email validation #1082

Merged
merged 4 commits into from
Mar 25, 2020

Conversation

filinvadim
Copy link

What does this do?

Fix email address segments legth validation.
Adds validation of email addresses with utf8 encoded characters.

Which issue(s) does this PR fix/relate to?

Resolves #798 .

List any changes that modify/break current functionality

External dependency: golang.org/x/net/idna.

Have you included tests for your changes?

Yes. Tests are extended.

Did you document any new/modified functionality?

No.

Notes

@filinvadim filinvadim requested a review from a team as a code owner March 24, 2020 14:51
@filinvadim filinvadim force-pushed the master branch 2 times, most recently from f7101e0 to 2252e7a Compare March 24, 2020 15:22
Copy link
Contributor

@manuio manuio left a comment

Choose a reason for hiding this comment

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

LGTM!

@codecov-io
Copy link

codecov-io commented Mar 24, 2020

Codecov Report

Merging #1082 into master will not change coverage by %.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1082   +/-   ##
=======================================
  Coverage   77.97%   77.97%           
=======================================
  Files          95       95           
  Lines        6698     6698           
=======================================
  Hits         5223     5223           
  Misses       1161     1161           
  Partials      314      314           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a2d70c8...3cb3ee5. Read the comment docs.

users/users.go Outdated

at := strings.LastIndex(email, "@")
if at <= 0 || at > len(email)-3 {
if len(local) == 0 || len(host) == 0 {
Copy link
Contributor

@manuio manuio Mar 24, 2020

Choose a reason for hiding this comment

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

Wait, we are not checking the extension anymore. Or you revert this len(host) - 3 == 0 or you can maybe do an extra Split to know the real size of the extension.

users/users.go Outdated

if len(user) > 64 {
hs := strings.Split(host, ".")
if len(es) != 2 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix len(hs)

users/users.go Outdated
return false
}

if len(local) > maxLocalLen || len(host) > maxHostLen {
Copy link
Contributor

@manuio manuio Mar 24, 2020

Choose a reason for hiding this comment

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

Please, add here a maxExtensionLen check

users/users.go Outdated

user := email[:at]
host := email[at+1:]
if len(local) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would do if len(local) == 0 || len(local) > maxLocalLen{ here

users/users.go Outdated
}
domain, ext := hs[0], hs[1]

if len(domain) == 0 || len(ext) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

and here if len(domain) == 0 || len(domain) > maxDomainLen

users/users.go Outdated
return false
}

if len(ext) > maxTLDLen {
Copy link
Contributor

Choose a reason for hiding this comment

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

and finally here if len(ext) == 0 || len(ext) > maxTLDLen

Signed-off-by: Vadim Filin <[email protected]>
@filinvadim
Copy link
Author

Let's stop here.

@drasko
Copy link
Contributor

drasko commented Mar 24, 2020

@filinvadim how should I understand this comment? Maybe you wanted to say "Thanks @manuio for taking your time in reviewing my PR, I understand that Mainflux is high-quality project that demands though peer-reviews and skills and patience are needed to get my PR to the adequate level to be accepted"?

@filinvadim
Copy link
Author

@drasko i did several out of issue scope changes and then I stopped.
@manuio thanks for taking your time in reviewing my PR! You’re great!
Feel free to merge it or not.

@drasko
Copy link
Contributor

drasko commented Mar 24, 2020

@filinvadim of course it will not be merged, not until all remarks are resolved. And this is only one reviewer/maintainter, there are several of us.

I am closing the issue, I hope this also clarifies why you and other in the industry can trust Mainflux code.

@drasko drasko closed this Mar 24, 2020
@filinvadim
Copy link
Author

Fixed.

@manuio manuio reopened this Mar 24, 2020
users/users.go Outdated
}
local, host := es[0], es[1]

if len(local) == 0 || len(local) > maxLocalLen {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, replace all len(local) == 0 by local == ""

},
"validate user with too long email tld": {
user: users.User{
Email: "user@example.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
Copy link
Contributor

@manuio manuio Mar 24, 2020

Choose a reason for hiding this comment

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

This and specially the next one are too long. You need a function here. We already did in other places things like:

letters = "abcdefghijklmnopqrstuvwxyz"
func randomString(n int) string {
	b := make([]byte, n)
	for i := range b {
		b[i] = letters[rand.Intn(len(letters))]
	}
	return string(b)
}

longDomain := randomString(maxDomainLen + 1)

Signed-off-by: Vadim Filin <[email protected]>
Copy link
Contributor

@manuio manuio left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@drasko drasko left a comment

Choose a reason for hiding this comment

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

LGTM

@manuio manuio merged commit b8818c4 into absmach:master Mar 25, 2020
@manuio
Copy link
Contributor

manuio commented Mar 25, 2020

Thank you @filinvadim !

manuio pushed a commit that referenced this pull request Oct 12, 2020
* Add utf8 support for email validation

Signed-off-by: Vadim Filin <[email protected]>

* Fix review comments

Signed-off-by: Vadim Filin <[email protected]>

* Refactor

Signed-off-by: Vadim Filin <[email protected]>

Co-authored-by: Drasko DRASKOVIC <[email protected]>
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.

Length of an email validation
4 participants