#956 Non-ASCII characters in external links

This commit is contained in:
Karel Pičman 2019-01-23 17:10:50 +01:00
parent 689b2dc793
commit 481edb9ae9
2 changed files with 5 additions and 3 deletions

View File

@ -25,12 +25,14 @@ class DmsfUrlValidator < ActiveModel::EachValidator
if record.target_type == 'DmsfUrl'
begin
if value.present?
URI.parse value
# TODO : This prevents from entering valid URLs with non-ASCII characters sue as: 'https://www.google.com/search?q=寿司'
#URI.parse value
else
record.errors.add attribute, :invalid
end
rescue URI::InvalidURIError
rescue URI::InvalidURIError => e
record.errors.add attribute, :invalid
Rails.logger.error e.message
end
end
end

View File

@ -113,7 +113,7 @@ class DmsfLinksTest < RedmineDmsf::Test::UnitTest
def test_validate_external_url
@file_link.target_type = 'DmsfUrl'
@file_link.external_url = 'htt ps://abc.xyz'
@file_link.external_url = ''
assert !@file_link.save,
"External URL link #{@file_link.name} should have not been saved"
assert_equal 1, @file_link.errors.size