Treat non-ascii URLs in UrlValidator.

This commit is contained in:
Guo Xiang Tan
2017-12-21 14:22:55 +08:00
parent 6ecf37c482
commit 4b51871f6a
2 changed files with 8 additions and 1 deletions

View File

@ -5,7 +5,12 @@ class UrlValidator < ActiveModel::EachValidator
begin
uri = URI.parse(value)
uri.is_a?(URI::HTTP) && !uri.host.nil? && uri.host.include?(".")
rescue
rescue URI::InvalidURIError => e
if (e.message =~ /URI must be ascii only/)
value = URI.encode(value)
retry
end
nil
end