When setting the allowed hosts for embedding, I get this error: Host is invalid.
This is because it is not passing this regex in the source code, line 26 in the source code of embeddable_host.rb: Link
def host_must_be_valid
if host !~ /\A[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,7}(:[0-9]{1,5})?(\/.*)?\Z/i &&
host !~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/
errors.add(:host, I18n.t('errors.messages.invalid'))
end
end
This regex only passes if the TLD is seven characters long or fewer. There are many TLDs that are longer than that nowadays, for instance:
Because I havenât decided what I think about CLAs in general or this one in particular. Also, I have not tested the fix. It should be fairly easy for someone who is fine with the CLA and who has already used to getting Discourse to build and to run tests.
def host_must_be_valid
if host !~ /\A[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,70}(:[0-9]{1,5})?(\/.*)?\Z/i &&
host !~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/
errors.add(:host, I18n.t('errors.messages.invalid'))
end
end
There you go. I changed 7 to 70. I release my changes under the CC0 license by Creative Commons and under the public domain.
A lot of code touches âhostâ and it is hoped that allowing more characters wonât break anything eg.
an HTML element thats CSS doesnât account for longer names.
a database table field that might truncate or null longer names.
other code that uses the value, eg. something like âreverse string positionâ
I made up a fake domain
âkleinfeltersville.travelersinsuranceâ
and it didnât break the Admin â Settings â Onebox UI
But I could use your help in trying to embed a real domain.
My, from memory, understanding of the rules of DNS labels are:
All labels are 1 to 63 characters, case insensitive A to Z, 0 to 9 and - (hyphen), all from ASCII.
No labels may start with a hyphen.
No top level domain label may start with a number.
That means a regexp for a valid domain name would look like: