User Preference 'Website' does not allow new TLDs

(James North) #1

Even though Discourse is hosted on my new TLD domain ‘’, it will not allow the website ‘’ in the user preferences.

It says that the website is invalid.

Version v1.7.0.beta3 +100

Photography Domain Invalid as Website on Profile
(cpradio) #2

Here is the relevant line

Changing the 2,10 to 2, would permit any length, but not sure if that would be the right modification for this.

(Eli the Bearded) #3

I have many questions about that RE.

Here’s a fragment to match a DNS label (other than top-level):


What it is doing:

  • a label must start with a letter or number: [a-z0-9]
  • you can have letters, numbers and hyphens in the middle: [a-z0-9-]{0,61}
    • double hyphens are allowed
    • a label can be up to 63 characters long
  • a label must end with a letter or number: [a-z0-9]

The rules for a TLD are the same, except that all numeric is not allowed.

No number in first position (one character label okay): /([a-z]([a-z0-9-]{0,61}[a-z0-9])?)/i
No number in last position (two character minimum): /[a-z0-9][a-z0-9-]{0,61}[a-z]/i
At least one letter in middle part (hacky for making RE readable): /[a-z0-9][a-z0-9-]{1,30}[a-z]([a-z0-9-]{0,30}[a-z0-9])?/i


The hacky one could be rewritten to all compliant strings, but it is ugly to enforce a letter somewhere while also enforcing a length restriction. There will be a ton of |s in the proper answer.

Combined hostname RE: (labelpart\.)+(tldpart1|tldpart2|tldpart3) :


And final combined WEBSITE_REGEXP:

WEBSITE_REGEXP = /(^$)|(^(http|https):\/\/([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+(([a-z]([a-z0-9-]{0,61}[a-z0-9])?)|[a-z0-9][a-z0-9-]{0,61}[a-z]|[a-z0-9][a-z0-9-]{1,30}[a-z]([a-z0-9-]{0,30}[a-z0-9])?\/.*)?$)/ix

(The syntax highlighter gets confused by the “Combined” line.)

Does /x to ruby mean the same as /x to perl? If so, in-line comments and a reformat should be added.

(Eli the Bearded) #4

It occurs to me that I stated that correctly, but did not code it correctly. When the dot-com billionaire who remembers his script kiddie roots registers the 1-3-3-7 TLD (for the ‘leet’ email address of i@m.1-3-3-7), TLD part 3 above would find no letters and deny it. The fix should be obvious.

(James North) #5

Just giving this one a bit of a bump.

It seems as though the admin area does allow new TLDs in company domain and in contact email.

Are they being validated though, or do they allow anything?

If the former, perhaps whatever that validation is will work perfectly well in the user preferences area.

(James North) #6

Bumping this one again.

Still cannot change website parameter in user profile to new TLDs - tells user the address is invalid.

(Jeff Atwood) #7

Sure @falco can you add this one to your list please? We should have centralized logic for this check…

(James North) #8

This is still an issue for me on latest.

(Rafael dos Santos Silva) #9

Yeah I made a fix to this, but using the current PublicSuffix gem is a memory hog, so we reverted.

Long term, we want to create a optimized PublicSuffix gem to fix this, and will also use it fix here.

(Jeff Atwood) #10

I do not follow, why do we need to validate every domain TLD? Just allow the text pattern…

(James North) #11

Almost a year later - still the same.

Cannot add new TLDs to personal preference ‘website’ field.

Reckon a plain old text field is all it needs?

(Eli the Bearded) #12

I’m looking at the code right now. The regexp highlighted earlier in the topic is an easy fix.

It still needs to pass user website whitelist, if set. I don’t know how often that is set.

(Régis Hanol) #13

Had to fix the regexp as it was allowing “http://

Photography Domain Invalid as Website on Profile
(Eli the Bearded) #14

Teach me to try to REGEXP at near midnight. :smile:

(Jeff Atwood) #15