@@ -202,19 +202,19 module Redmine | |||||
202 | # %m1%, %m2%... => capture groups matches of the custom field regexp if defined |
|
202 | # %m1%, %m2%... => capture groups matches of the custom field regexp if defined | |
203 | def url_from_pattern(custom_field, value, customized) |
|
203 | def url_from_pattern(custom_field, value, customized) | |
204 | url = custom_field.url_pattern.to_s.dup |
|
204 | url = custom_field.url_pattern.to_s.dup | |
205 | url.gsub!('%value%') {value.to_s} |
|
205 | url.gsub!('%value%') {URI.encode value.to_s} | |
206 | url.gsub!('%id%') {customized.id.to_s} |
|
206 | url.gsub!('%id%') {URI.encode customized.id.to_s} | |
207 | url.gsub!('%project_id%') {(customized.respond_to?(:project) ? customized.project.try(:id) : nil).to_s} |
|
207 | url.gsub!('%project_id%') {URI.encode (customized.respond_to?(:project) ? customized.project.try(:id) : nil).to_s} | |
208 | url.gsub!('%project_identifier%') {(customized.respond_to?(:project) ? customized.project.try(:identifier) : nil).to_s} |
|
208 | url.gsub!('%project_identifier%') {URI.encode (customized.respond_to?(:project) ? customized.project.try(:identifier) : nil).to_s} | |
209 | if custom_field.regexp.present? |
|
209 | if custom_field.regexp.present? | |
210 | url.gsub!(%r{%m(\d+)%}) do |
|
210 | url.gsub!(%r{%m(\d+)%}) do | |
211 | m = $1.to_i |
|
211 | m = $1.to_i | |
212 | if matches ||= value.to_s.match(Regexp.new(custom_field.regexp)) |
|
212 | if matches ||= value.to_s.match(Regexp.new(custom_field.regexp)) | |
213 | matches[m].to_s |
|
213 | URI.encode matches[m].to_s | |
214 | end |
|
214 | end | |
215 | end |
|
215 | end | |
216 | end |
|
216 | end | |
217 |
|
|
217 | url | |
218 | end |
|
218 | end | |
219 | protected :url_from_pattern |
|
219 | protected :url_from_pattern | |
220 |
|
220 |
@@ -82,4 +82,20 class Redmine::FieldFormatTest < ActionView::TestCase | |||||
82 | assert_equal "foo bar", field.format.formatted_custom_value(self, custom_value, false) |
|
82 | assert_equal "foo bar", field.format.formatted_custom_value(self, custom_value, false) | |
83 | assert_equal '<a href="http://foo/foo%20bar">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true) |
|
83 | assert_equal '<a href="http://foo/foo%20bar">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true) | |
84 | end |
|
84 | end | |
|
85 | ||||
|
86 | def test_text_field_with_url_pattern_should_not_encode_url_pattern | |||
|
87 | field = IssueCustomField.new(:field_format => 'string', :url_pattern => 'http://foo/bar#anchor') | |||
|
88 | custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "1") | |||
|
89 | ||||
|
90 | assert_equal "1", field.format.formatted_custom_value(self, custom_value, false) | |||
|
91 | assert_equal '<a href="http://foo/bar#anchor">1</a>', field.format.formatted_custom_value(self, custom_value, true) | |||
|
92 | end | |||
|
93 | ||||
|
94 | def test_text_field_with_url_pattern_should_encode_values | |||
|
95 | field = IssueCustomField.new(:field_format => 'string', :url_pattern => 'http://foo/%value%#anchor') | |||
|
96 | custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "foo bar") | |||
|
97 | ||||
|
98 | assert_equal "foo bar", field.format.formatted_custom_value(self, custom_value, false) | |||
|
99 | assert_equal '<a href="http://foo/foo%20bar#anchor">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true) | |||
|
100 | end | |||
85 | end |
|
101 | end |
General Comments 0
You need to be logged in to leave comments.
Login now