diff --git a/app/models/embeddable_host.rb b/app/models/embeddable_host.rb index bc7f2f3e999..f94ce56b1b8 100644 --- a/app/models/embeddable_host.rb +++ b/app/models/embeddable_host.rb @@ -40,7 +40,7 @@ class EmbeddableHost < ActiveRecord::Base 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/ && + 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')) end diff --git a/spec/models/embeddable_host_spec.rb b/spec/models/embeddable_host_spec.rb index fe731328513..700478871cd 100644 --- a/spec/models/embeddable_host_spec.rb +++ b/spec/models/embeddable_host_spec.rb @@ -38,6 +38,12 @@ describe EmbeddableHost do expect(eh.host).to eq('localhost:8080') end + it "supports ports for ip addresses" do + eh = EmbeddableHost.new(host: '192.168.0.1:3000') + expect(eh).to be_valid + expect(eh.host).to eq('192.168.0.1:3000') + end + it "supports subdomains of localhost" do eh = EmbeddableHost.new(host: 'discourse.localhost') expect(eh).to be_valid