]> source.dussan.org Git - redmine.git/commitdiff
Merged r22205 from trunk to 4.2-stable (#38464).
authorGo MAEDA <maeda@farend.jp>
Fri, 21 Apr 2023 03:37:54 +0000 (03:37 +0000)
committerGo MAEDA <maeda@farend.jp>
Fri, 21 Apr 2023 03:37:54 +0000 (03:37 +0000)
git-svn-id: https://svn.redmine.org/redmine/branches/4.2-stable@22207 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 05dc21f4b222e283b59faff4a25466d83287479e..64c3a8857eb7a0f4c6425f804aa1b53e55c7e313 100644 (file)
@@ -273,15 +273,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
@@ -289,7 +289,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
index bda14e848a6599628bde7889464947947fa47336..d9cb12b5334c50d035945167d9687b3dd68ea3d4 100644 (file)
@@ -86,6 +86,14 @@ class Redmine::FieldFormatTest < ActionView::TestCase
     assert_equal '<a class="external" 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_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 class="external" href="http://foo/foo%20:bar">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")