Defect #24821 ยป 0001-Allow-mailto-in-custom-field-URL-patterns.patch
| lib/redmine/field_format.rb | ||
|---|---|---|
|
def validate_custom_field(custom_field)
|
||
|
errors = []
|
||
|
pattern = custom_field.url_pattern
|
||
|
if pattern.present? && !uri_with_safe_scheme?(url_pattern_without_tokens(pattern))
|
||
|
if pattern.present? && !url_pattern_with_safe_scheme?(pattern)
|
||
|
errors << [:url_pattern, :invalid]
|
||
|
end
|
||
|
errors
|
||
| ... | ... | |
|
end
|
||
|
protected :url_pattern_without_tokens
|
||
|
# Checks only the scheme because the URL pattern is not a complete URI
|
||
|
# until the tokens are substituted (e.g. "mailto:%value%")
|
||
|
def url_pattern_with_safe_scheme?(url_pattern)
|
||
|
scheme = URI.split(url_pattern_without_tokens(url_pattern)).first
|
||
|
Redmine::Helpers::URL::SAFE_SCHEMES.include?(scheme)
|
||
|
rescue URI::InvalidURIError
|
||
|
false
|
||
|
end
|
||
|
protected :url_pattern_with_safe_scheme?
|
||
|
def edit_tag(view, tag_id, tag_name, custom_value, options={})
|
||
|
view.text_field_tag(tag_name, custom_value.value, options.merge(:id => tag_id))
|
||
|
end
|
||
| lib/redmine/helpers/url.rb | ||
|---|---|---|
|
module Redmine
|
||
|
module Helpers
|
||
|
module URL
|
||
|
SAFE_SCHEMES = ['http', 'https', 'ftp', 'mailto', nil].freeze
|
||
|
# safe for resources fetched without user interaction?
|
||
|
def uri_with_safe_scheme?(uri, schemes = ['http', 'https', 'ftp', 'mailto', nil])
|
||
|
def uri_with_safe_scheme?(uri, schemes = SAFE_SCHEMES)
|
||
|
# URLs relative to the current document or document root (without a protocol
|
||
|
# separator, should be harmless
|
||
|
return true unless uri.to_s.include? ":"
|
||
| test/unit/lib/redmine/field_format/field_format_test.rb | ||
|---|---|---|
|
assert_save field
|
||
|
end
|
||
|
def test_should_validate_url_pattern_with_mailto_scheme
|
||
|
field = IssueCustomField.new(:field_format => 'string', :name => 'Email', :url_pattern => 'mailto:%value%')
|
||
|
assert_save field
|
||
|
end
|
||
|
def test_should_not_validate_url_pattern_with_unsafe_scheme
|
||
|
field = IssueCustomField.new(:field_format => 'string', :name => 'URL', :url_pattern => 'foo://foo/%value%')
|
||
|
assert !field.save
|
||