2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

Merge pull request #5451 from tgxworld/treat_non_ascii_urls_as_valid

Treat non-ascii URLs in `UrlValidator`.
This commit is contained in:
Guo Xiang Tan 2017-12-27 14:14:20 +08:00 committed by GitHub
commit 805d1c25d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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