Merge pull request #5451 from tgxworld/treat_non_ascii_urls_as_valid
Treat non-ascii URLs in `UrlValidator`.
This commit is contained in:
commit
805d1c25d3
|
@ -5,7 +5,12 @@ class UrlValidator < ActiveModel::EachValidator
|
||||||
begin
|
begin
|
||||||
uri = URI.parse(value)
|
uri = URI.parse(value)
|
||||||
uri.is_a?(URI::HTTP) && !uri.host.nil? && uri.host.include?(".")
|
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
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,8 @@ RSpec.describe UrlValidator do
|
||||||
[
|
[
|
||||||
"http://discourse.productions",
|
"http://discourse.productions",
|
||||||
"https://google.com",
|
"https://google.com",
|
||||||
|
'http://xn--nw2a.xn--j6w193g/',
|
||||||
|
"http://見.香港/",
|
||||||
].each do |valid_url|
|
].each do |valid_url|
|
||||||
it "#{valid_url} should be valid" do
|
it "#{valid_url} should be valid" do
|
||||||
record.website = valid_url
|
record.website = valid_url
|
||||||
|
|
Loading…
Reference in New Issue