##// END OF EJS Templates
Merged r15846 (#23841)....
Jean-Philippe Lang -
r15487:ae4bfd533451
parent child
Show More
@@ -176,19 +176,19 module Redmine
176 # %m1%, %m2%... => capture groups matches of the custom field regexp if defined
176 # %m1%, %m2%... => capture groups matches of the custom field regexp if defined
177 def url_from_pattern(custom_field, value, customized)
177 def url_from_pattern(custom_field, value, customized)
178 url = custom_field.url_pattern.to_s.dup
178 url = custom_field.url_pattern.to_s.dup
179 url.gsub!('%value%') {value.to_s}
179 url.gsub!('%value%') {URI.encode value.to_s}
180 url.gsub!('%id%') {customized.id.to_s}
180 url.gsub!('%id%') {URI.encode customized.id.to_s}
181 url.gsub!('%project_id%') {(customized.respond_to?(:project) ? customized.project.try(:id) : nil).to_s}
181 url.gsub!('%project_id%') {URI.encode (customized.respond_to?(:project) ? customized.project.try(:id) : nil).to_s}
182 url.gsub!('%project_identifier%') {(customized.respond_to?(:project) ? customized.project.try(:identifier) : nil).to_s}
182 url.gsub!('%project_identifier%') {URI.encode (customized.respond_to?(:project) ? customized.project.try(:identifier) : nil).to_s}
183 if custom_field.regexp.present?
183 if custom_field.regexp.present?
184 url.gsub!(%r{%m(\d+)%}) do
184 url.gsub!(%r{%m(\d+)%}) do
185 m = $1.to_i
185 m = $1.to_i
186 if matches ||= value.to_s.match(Regexp.new(custom_field.regexp))
186 if matches ||= value.to_s.match(Regexp.new(custom_field.regexp))
187 matches[m].to_s
187 URI.encode matches[m].to_s
188 end
188 end
189 end
189 end
190 end
190 end
191 URI.encode(url)
191 url
192 end
192 end
193 protected :url_from_pattern
193 protected :url_from_pattern
194
194
@@ -67,4 +67,20 class Redmine::FieldFormatTest < ActionView::TestCase
67 assert_equal "foo bar", field.format.formatted_custom_value(self, custom_value, false)
67 assert_equal "foo bar", field.format.formatted_custom_value(self, custom_value, false)
68 assert_equal '<a href="http://foo/foo%20bar">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true)
68 assert_equal '<a href="http://foo/foo%20bar">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true)
69 end
69 end
70
71 def test_text_field_with_url_pattern_should_not_encode_url_pattern
72 field = IssueCustomField.new(:field_format => 'string', :url_pattern => 'http://foo/bar#anchor')
73 custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "1")
74
75 assert_equal "1", field.format.formatted_custom_value(self, custom_value, false)
76 assert_equal '<a href="http://foo/bar#anchor">1</a>', field.format.formatted_custom_value(self, custom_value, true)
77 end
78
79 def test_text_field_with_url_pattern_should_encode_values
80 field = IssueCustomField.new(:field_format => 'string', :url_pattern => 'http://foo/%value%#anchor')
81 custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "foo bar")
82
83 assert_equal "foo bar", field.format.formatted_custom_value(self, custom_value, false)
84 assert_equal '<a href="http://foo/foo%20bar#anchor">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true)
85 end
70 end
86 end
General Comments 0
You need to be logged in to leave comments. Login now