mirror of
https://github.com/redmine/redmine.git
synced 2025-11-12 08:16:03 +01:00
Make robust Redmine::Helpers::URL#uri_with_safe_scheme? (#27114)
Patch by okkez. git-svn-id: http://svn.redmine.org/redmine/trunk@17035 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -27,7 +27,7 @@ module Redmine
|
||||
|
||||
# Other URLs need to be parsed
|
||||
schemes.include? URI.parse(uri).scheme
|
||||
rescue URI::InvalidURIError
|
||||
rescue URI::Error
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
17
test/unit/lib/redmine/helpers/url_test.rb
Normal file
17
test/unit/lib/redmine/helpers/url_test.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
require File.expand_path('../../../../../test_helper', __FILE__)
|
||||
|
||||
class URLTest < ActiveSupport::TestCase
|
||||
include Redmine::Helpers::URL
|
||||
|
||||
def test_uri_with_safe_scheme
|
||||
assert uri_with_safe_scheme?("http://example.com/")
|
||||
assert uri_with_safe_scheme?("https://example.com/")
|
||||
assert uri_with_safe_scheme?("ftp://example.com/index.html")
|
||||
assert uri_with_safe_scheme?("mailto:root@example.com")
|
||||
end
|
||||
|
||||
def test_uri_with_safe_scheme_invalid_component
|
||||
assert_not uri_with_safe_scheme?("httpx://example.com/")
|
||||
assert_not uri_with_safe_scheme?("mailto:root@")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user