1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-01-31 11:37:14 +00:00

Rendering a custom field with a URL pattern set and containing " :" in the value raises Addressable::URI::InvalidURIError (#38464).

Patch by Go MAEDA.


git-svn-id: https://svn.redmine.org/redmine/trunk@22205 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA 2023-04-21 03:06:06 +00:00
parent 1099623634
commit b1510836b0
2 changed files with 13 additions and 5 deletions

View File

@ -276,15 +276,15 @@ module Redmine
# %m1%, %m2%... => capture groups matches of the custom field regexp if defined
def url_from_pattern(custom_field, value, customized)
url = custom_field.url_pattern.to_s.dup
url.gsub!('%value%') {Addressable::URI.encode value.to_s}
url.gsub!('%id%') {Addressable::URI.encode customized.id.to_s}
url.gsub!('%value%') {Addressable::URI.encode_component value.to_s}
url.gsub!('%id%') {Addressable::URI.encode_component customized.id.to_s}
url.gsub!('%project_id%') do
Addressable::URI.encode(
Addressable::URI.encode_component(
(customized.respond_to?(:project) ? customized.project.try(:id) : nil).to_s
)
end
url.gsub!('%project_identifier%') do
Addressable::URI.encode(
Addressable::URI.encode_component(
(customized.respond_to?(:project) ? customized.project.try(:identifier) : nil).to_s
)
end
@ -292,7 +292,7 @@ module Redmine
url.gsub!(%r{%m(\d+)%}) do
m = $1.to_i
if matches ||= value.to_s.match(Regexp.new(custom_field.regexp))
Addressable::URI.encode matches[m].to_s
Addressable::URI.encode_component matches[m].to_s
end
end
end

View File

@ -90,6 +90,14 @@ class Redmine::FieldFormatTest < ActionView::TestCase
assert_equal '<a href="http://foo/foo%20bar" class="external">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true)
end
def test_text_field_with_url_pattern_and_value_containing_a_colon_preceded_by_a_space_should_format_as_link
field = IssueCustomField.new(:field_format => 'string', :url_pattern => 'http://foo/%value%')
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => 'foo :bar')
assert_equal 'foo :bar', field.format.formatted_custom_value(self, custom_value, false)
assert_equal '<a href="http://foo/foo%20:bar" class="external">foo :bar</a>', field.format.formatted_custom_value(self, custom_value, true)
end
def test_text_field_with_url_pattern_should_not_encode_url_pattern
field = IssueCustomField.new(:field_format => 'string', :url_pattern => 'http://foo/bar#anchor')
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "1")