mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 03:10:11 +08:00
Merge pull request #4342 from acshi/embeddedhost-localhost
Allow localhost as an embeddable host
This commit is contained in:
commit
fb1b119462
|
@ -25,7 +25,8 @@ 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})\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
|
||||
end
|
||||
|
|
|
@ -26,6 +26,29 @@ describe EmbeddableHost do
|
|||
expect(eh.host).to eq('192.168.0.1')
|
||||
end
|
||||
|
||||
it "supports localhost" do
|
||||
eh = EmbeddableHost.new(host: 'localhost')
|
||||
expect(eh).to be_valid
|
||||
expect(eh.host).to eq('localhost')
|
||||
end
|
||||
|
||||
it "supports ports of localhost" do
|
||||
eh = EmbeddableHost.new(host: 'localhost:8080')
|
||||
expect(eh).to be_valid
|
||||
expect(eh.host).to eq('localhost:8080')
|
||||
end
|
||||
|
||||
it "supports subdomains of localhost" do
|
||||
eh = EmbeddableHost.new(host: 'discourse.localhost')
|
||||
expect(eh).to be_valid
|
||||
expect(eh.host).to eq('discourse.localhost')
|
||||
end
|
||||
|
||||
it "rejects misspellings of localhost" do
|
||||
eh = EmbeddableHost.new(host: 'alocalhost')
|
||||
expect(eh).not_to be_valid
|
||||
end
|
||||
|
||||
describe "allows_embeddable_host" do
|
||||
let!(:host) { Fabricate(:embeddable_host) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user