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

Make ISEMAIL and ISURL more flexible for longer TLD #834

Merged
merged 5 commits into from
Jan 31, 2024

Conversation

vviers
Copy link
Collaborator

@vviers vviers commented Jan 30, 2024

Context

More and more local governments around the world use custom TLD (.amsterdam, .melbourne, .corsica, .nyc just to name a few, full list here) and the ISEMAIL function doesn't consider email@cityof.{TLD} as valid if it is of length > 6.

Proposal

I know validating emails is very tricky and that there is no "right way" to do this, but I think allowing longer TLDs makes sense, especially since application for gTLD was made easier back in 2011 and there are now more than 1400 TLDs (out of which 466 are longer than 6 characters).

I used 24 as the upper limit as that's the current max, though in theory TLDs could be 63 bytes as per RFC 1034.

Check my numbers

Here's a quick python script that backs up my numbers

import requests
r = requests.get("http://data.iana.org/TLD/tlds-alpha-by-domain.txt")
tlds = r.text.split("\n")[1:]

# Longest TLD
max(tlds, key=len)
# > 'XN--VERMGENSBERATUNG-PWB'
len(max(tlds, key=len))
# > 24

# TLDs longer than 6
sum([len(tld) > 6 for tld in tlds])
# > 466

# Total number of TLDs
len(tlds)
# > 1453

@vviers vviers requested review from berhalak and paulfitz January 30, 2024 11:29
paulfitz
paulfitz previously approved these changes Jan 30, 2024
Copy link
Member

@paulfitz paulfitz left a comment

Choose a reason for hiding this comment

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

Thanks a lot @vviers ! Makes sense.

@paulfitz paulfitz dismissed their stale review January 30, 2024 13:55

There seems to be still a genuine test failure

@vviers
Copy link
Collaborator Author

vviers commented Jan 30, 2024

I think I found the issue, I didn't realize docstrings were actual tests

@vviers vviers changed the title Make ISEMAIL more flexible for longer TLD Make ISEMAIL and ISURL more flexible for longer TLD Jan 30, 2024
@vviers
Copy link
Collaborator Author

vviers commented Jan 30, 2024

Weird... the "should distinguish valid and invalid emails" tests pass on my machine but not here

@vviers
Copy link
Collaborator Author

vviers commented Jan 31, 2024

I found what was wrong, I needed to update the JS isEmail function in app/common/gutil.ts as well.

@paulfitz I can't help but notice that this function is never called in the code, do you know if it is still needed ? Is this used in your enterprise codebase perhaps ?

@vviers vviers requested a review from paulfitz January 31, 2024 15:15
@paulfitz
Copy link
Member

@paulfitz I can't help but notice that this function is never called in the code, do you know if it is still needed ? Is this used in your enterprise codebase perhaps ?

Just checked, we don't use it. It was introduced in 2018, and used in an invite mechanism that has since been ripped out. So it could just be removed. Thanks for spotting this.

Copy link
Member

@paulfitz paulfitz left a comment

Choose a reason for hiding this comment

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

Looks good, thanks @vviers !

@paulfitz paulfitz merged commit 6ff4f43 into gristlabs:main Jan 31, 2024
12 of 13 checks passed
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