FIX: Allow multiple hyphens in host (#10078)

* FIX: Allow multiple hyphens in host

* FIX: added spec for multiple hyphens
This commit is contained in:
Cassius 2020-06-19 00:58:47 +07:00 committed by GitHub
parent 494a27dc27
commit d13d5e2b99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -61,7 +61,7 @@ class EmbeddableHost < ActiveRecord::Base
end
def host_must_be_valid
if host !~ /\A[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,24}(:[0-9]{1,5})?(\/.*)?\Z/i &&
if host !~ /\A[a-z0-9]+([\-\.]+{1}[a-z0-9]+)*\.[a-z]{2,24}(:[0-9]{1,5})?(\/.*)?\Z/i &&
host !~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})(:[0-9]{1,5})?(\/.*)?\Z/ &&
host !~ /\A([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.)?localhost(\:[0-9]{1,5})?(\/.*)?\Z/i
errors.add(:host, I18n.t('errors.messages.invalid'))

View File

@ -52,6 +52,12 @@ describe EmbeddableHost do
expect(eh.host).to eq('discourse.localhost')
end
it "supports multiple hyphens" do
eh = EmbeddableHost.new(host: 'deploy-preview-1--example.example.app')
expect(eh).to be_valid
expect(eh.host).to eq('deploy-preview-1--example.example.app')
end
it "rejects misspellings of localhost" do
eh = EmbeddableHost.new(host: 'alocalhost')
expect(eh).not_to be_valid