Defect #38464 ยป 38464.patch
lib/redmine/field_format.rb | ||
---|---|---|
276 | 276 |
# %m1%, %m2%... => capture groups matches of the custom field regexp if defined |
277 | 277 |
def url_from_pattern(custom_field, value, customized) |
278 | 278 |
url = custom_field.url_pattern.to_s.dup |
279 |
url.gsub!('%value%') {Addressable::URI.encode value.to_s} |
|
280 |
url.gsub!('%id%') {Addressable::URI.encode customized.id.to_s} |
|
279 |
url.gsub!('%value%') {Addressable::URI.encode_component value.to_s}
|
|
280 |
url.gsub!('%id%') {Addressable::URI.encode_component customized.id.to_s}
|
|
281 | 281 |
url.gsub!('%project_id%') do |
282 |
Addressable::URI.encode( |
|
282 |
Addressable::URI.encode_component(
|
|
283 | 283 |
(customized.respond_to?(:project) ? customized.project.try(:id) : nil).to_s |
284 | 284 |
) |
285 | 285 |
end |
286 | 286 |
url.gsub!('%project_identifier%') do |
287 |
Addressable::URI.encode( |
|
287 |
Addressable::URI.encode_component(
|
|
288 | 288 |
(customized.respond_to?(:project) ? customized.project.try(:identifier) : nil).to_s |
289 | 289 |
) |
290 | 290 |
end |
... | ... | |
292 | 292 |
url.gsub!(%r{%m(\d+)%}) do |
293 | 293 |
m = $1.to_i |
294 | 294 |
if matches ||= value.to_s.match(Regexp.new(custom_field.regexp)) |
295 |
Addressable::URI.encode matches[m].to_s |
|
295 |
Addressable::URI.encode_component matches[m].to_s
|
|
296 | 296 |
end |
297 | 297 |
end |
298 | 298 |
end |
test/unit/lib/redmine/field_format/field_format_test.rb | ||
---|---|---|
90 | 90 |
assert_equal '<a href="http://foo/foo%20bar" class="external">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true) |
91 | 91 |
end |
92 | 92 | |
93 |
def test_text_field_with_url_pattern_and_value_containing_a_colon_preceded_by_a_space_should_format_as_link |
|
94 |
field = IssueCustomField.new(:field_format => 'string', :url_pattern => 'http://foo/%value%') |
|
95 |
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "foo :bar") |
|
96 | ||
97 |
assert_equal "foo :bar", field.format.formatted_custom_value(self, custom_value, false) |
|
98 |
assert_equal '<a href="http://foo/foo%20:bar" class="external">foo :bar</a>', field.format.formatted_custom_value(self, custom_value, true) |
|
99 |
end |
|
100 | ||
93 | 101 |
def test_text_field_with_url_pattern_should_not_encode_url_pattern |
94 | 102 |
field = IssueCustomField.new(:field_format => 'string', :url_pattern => 'http://foo/bar#anchor') |
95 | 103 |
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "1") |