]> source.dussan.org Git - redmine.git/commitdiff
Merged r15846 (#23841).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 2 Oct 2016 10:13:15 +0000 (10:13 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 2 Oct 2016 10:13:15 +0000 (10:13 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.1-stable@15869 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/field_format.rb
test/unit/lib/redmine/field_format/field_format_test.rb

index dcc26048e693c63229136e8bcb6e39dfc35382cd..02f21967a1b83e942410a47923b47ebba9a706a4 100644 (file)
@@ -176,19 +176,19 @@ 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%') {value.to_s}
-        url.gsub!('%id%') {customized.id.to_s}
-        url.gsub!('%project_id%') {(customized.respond_to?(:project) ? customized.project.try(:id) : nil).to_s}
-        url.gsub!('%project_identifier%') {(customized.respond_to?(:project) ? customized.project.try(:identifier) : nil).to_s}
+        url.gsub!('%value%') {URI.encode value.to_s}
+        url.gsub!('%id%') {URI.encode customized.id.to_s}
+        url.gsub!('%project_id%') {URI.encode (customized.respond_to?(:project) ? customized.project.try(:id) : nil).to_s}
+        url.gsub!('%project_identifier%') {URI.encode (customized.respond_to?(:project) ? customized.project.try(:identifier) : nil).to_s}
         if custom_field.regexp.present?
           url.gsub!(%r{%m(\d+)%}) do
             m = $1.to_i
             if matches ||= value.to_s.match(Regexp.new(custom_field.regexp))
-              matches[m].to_s
+              URI.encode matches[m].to_s
             end
           end
         end
-        URI.encode(url)
+        url
       end
       protected :url_from_pattern
 
index 08e167e701796d9e2a57ba91e6007ff9ca2ecd1d..c40ff196557d5eeaf1cdcc1c80f918ecbdfde492 100644 (file)
@@ -67,4 +67,20 @@ class Redmine::FieldFormatTest < ActionView::TestCase
     assert_equal "foo bar", field.format.formatted_custom_value(self, custom_value, false)
     assert_equal '<a href="http://foo/foo%20bar">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")
+
+    assert_equal "1", field.format.formatted_custom_value(self, custom_value, false)
+    assert_equal '<a href="http://foo/bar#anchor">1</a>', field.format.formatted_custom_value(self, custom_value, true)
+  end
+
+  def test_text_field_with_url_pattern_should_encode_values
+    field = IssueCustomField.new(:field_format => 'string', :url_pattern => 'http://foo/%value%#anchor')
+    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%20bar#anchor">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true)
+  end
 end