A platform for community discussion. Free, open, simple.
FIX: Allow multiple hyphens in host (#10078)
Cassiusd13d5e2b998e
diff --git a/app/models/embeddable_host.rb b/app/models/embeddable_host.rbindex 32781522c3e..7984c0a18f9 100644--- a/app/models/embeddable_host.rb+++ b/app/models/embeddable_host.rb@@ -61,7 +61,7 @@ class EmbeddableHost < ActiveRecord::Baseenddef 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/ierrors.add(:host, I18n.t('errors.messages.invalid'))diff --git a/spec/models/embeddable_host_spec.rb b/spec/models/embeddable_host_spec.rbindex 449c87aa2fd..66b81b9bd45 100644--- a/spec/models/embeddable_host_spec.rb+++ b/spec/models/embeddable_host_spec.rb@@ -52,6 +52,12 @@ describe EmbeddableHost doexpect(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" doeh = EmbeddableHost.new(host: 'alocalhost')expect(eh).not_to be_valid