diff --git a/lib/webhook_endpoint_validator.rb b/lib/webhook_endpoint_validator.rb index ba1c41220..b0ceb96bf 100644 --- a/lib/webhook_endpoint_validator.rb +++ b/lib/webhook_endpoint_validator.rb @@ -33,7 +33,7 @@ class WebhookEndpointValidator < ActiveModel::EachValidator return false if uri.nil? return false unless valid_scheme?(uri.scheme) - return false unless valid_host?(uri.host) + return false unless valid_host?(uri.hostname) return false unless valid_port?(uri.port) true diff --git a/test/unit/lib/webhook_endpoint_validator_test.rb b/test/unit/lib/webhook_endpoint_validator_test.rb index d5317f214..dd53b6c07 100644 --- a/test/unit/lib/webhook_endpoint_validator_test.rb +++ b/test/unit/lib/webhook_endpoint_validator_test.rb @@ -95,5 +95,13 @@ class WebhookEndpointValidatorTest < ActiveSupport::TestCase assert h.errors[:url].any? end end + + %w[ + [2001:0db8:85a3:0000:0000:8a2e:0370:7334] + 8.8.8.8 + ].each do |host| + h = TestModel.new "http://#{host}" + assert h.valid?, "URI host #{host} should be valid" + end end end