]> source.dussan.org Git - redmine.git/commitdiff
Links for custom field value don't have "external" class (#27024).
authorGo MAEDA <maeda@farend.jp>
Mon, 1 Jan 2018 06:18:01 +0000 (06:18 +0000)
committerGo MAEDA <maeda@farend.jp>
Mon, 1 Jan 2018 06:18:01 +0000 (06:18 +0000)
Patch by Go MAEDA.

git-svn-id: http://svn.redmine.org/redmine/trunk@17138 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/field_format.rb
test/unit/lib/redmine/field_format/field_format_test.rb
test/unit/lib/redmine/field_format/link_format_test.rb
test/unit/lib/redmine/field_format/list_format_test.rb
test/unit/lib/redmine/field_format/numeric_format_test.rb

index b597606748787052970c9f74295c6b0926579a72..bcf6ccc3d9b7c3fc41273e0cd4e8e8ad5c5b4260 100644 (file)
@@ -248,7 +248,10 @@ module Redmine
             url = url_from_pattern(custom_field, single_value, customized)
             [text, url]
           end
-          links = texts_and_urls.sort_by(&:first).map {|text, url| view.link_to_if uri_with_safe_scheme?(url), text, url}
+          links = texts_and_urls.sort_by(&:first).map do |text, url|
+            css_class = (url =~ /^https?:\/\//) ? 'external' : nil
+            view.link_to_if uri_with_safe_scheme?(url), text, url, :class => css_class
+          end
           links.join(', ').html_safe
         else
           casted
@@ -442,7 +445,8 @@ module Redmine
               url = "http://" + url
             end
           end
-          view.link_to value.to_s.truncate(40), url
+          css_class = (url =~ /^https?:\/\//) ? 'external' : nil
+          view.link_to value.to_s.truncate(40), url, :class => css_class
         else
           value.to_s
         end
index 631ac310f038d615f848da265725205a1bd249dd..f066389446d974b01b710c7767a2403f624475b0 100644 (file)
@@ -72,7 +72,7 @@ class Redmine::FieldFormatTest < ActionView::TestCase
     custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "bar")
 
     assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
-    assert_equal '<a href="http://foo/bar">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
+    assert_equal '<a class="external" href="http://foo/bar">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
   end
 
   def test_text_field_with_url_pattern_and_value_containing_a_space_should_format_as_link
@@ -80,7 +80,7 @@ class Redmine::FieldFormatTest < ActionView::TestCase
     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">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true)
+    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_should_not_encode_url_pattern
@@ -88,7 +88,7 @@ class Redmine::FieldFormatTest < ActionView::TestCase
     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)
+    assert_equal '<a class="external" 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
@@ -96,6 +96,6 @@ class Redmine::FieldFormatTest < ActionView::TestCase
     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)
+    assert_equal '<a class="external" href="http://foo/foo%20bar#anchor">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true)
   end
 end
index 311e75af0e17c75532d14e186ff6c4e259f9f277..d5758be17270e6999becd3a618a7eb0981734336 100644 (file)
@@ -24,7 +24,7 @@ class Redmine::LinkFieldFormatTest < ActionView::TestCase
     custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "bar")
 
     assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
-    assert_equal '<a href="http://foo/bar">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
+    assert_equal '<a class="external" href="http://foo/bar">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
   end
 
   def test_link_field_should_substitute_object_id_in_url
@@ -35,7 +35,7 @@ class Redmine::LinkFieldFormatTest < ActionView::TestCase
     custom_value = CustomValue.new(:custom_field => field, :customized => object, :value => "bar")
 
     assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
-    assert_equal '<a href="http://foo/10">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
+    assert_equal '<a class="external" href="http://foo/10">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
   end
 
   def test_link_field_should_substitute_project_id_in_url
@@ -48,7 +48,7 @@ class Redmine::LinkFieldFormatTest < ActionView::TestCase
     custom_value = CustomValue.new(:custom_field => field, :customized => object, :value => "bar")
 
     assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
-    assert_equal '<a href="http://foo/52">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
+    assert_equal '<a class="external" href="http://foo/52">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
   end
 
   def test_link_field_should_substitute_project_identifier_in_url
@@ -61,7 +61,7 @@ class Redmine::LinkFieldFormatTest < ActionView::TestCase
     custom_value = CustomValue.new(:custom_field => field, :customized => object, :value => "bar")
 
     assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
-    assert_equal '<a href="http://foo/foo_project-00">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
+    assert_equal '<a class="external" href="http://foo/foo_project-00">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
   end
 
   def test_link_field_should_substitute_regexp_groups
@@ -69,7 +69,7 @@ class Redmine::LinkFieldFormatTest < ActionView::TestCase
     custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "56-142")
 
     assert_equal "56-142", field.format.formatted_custom_value(self, custom_value, false)
-    assert_equal '<a href="http://foo/142/56">56-142</a>', field.format.formatted_custom_value(self, custom_value, true)
+    assert_equal '<a class="external" href="http://foo/142/56">56-142</a>', field.format.formatted_custom_value(self, custom_value, true)
   end
 
   def test_link_field_without_url_pattern_should_link_to_value
@@ -77,7 +77,7 @@ class Redmine::LinkFieldFormatTest < ActionView::TestCase
     custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "http://foo/bar")
 
     assert_equal "http://foo/bar", field.format.formatted_custom_value(self, custom_value, false)
-    assert_equal '<a href="http://foo/bar">http://foo/bar</a>', field.format.formatted_custom_value(self, custom_value, true)
+    assert_equal '<a class="external" href="http://foo/bar">http://foo/bar</a>', field.format.formatted_custom_value(self, custom_value, true)
   end
 
   def test_link_field_without_url_pattern_should_link_to_value_with_http_by_default
@@ -85,6 +85,6 @@ class Redmine::LinkFieldFormatTest < ActionView::TestCase
     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.bar">foo.bar</a>', field.format.formatted_custom_value(self, custom_value, true)
+    assert_equal '<a class="external" href="http://foo.bar">foo.bar</a>', field.format.formatted_custom_value(self, custom_value, true)
   end
 end
index 9c23fd07559bb6e385ff60d5b35572416bb1d702..fc2459d4a5c58fddf0423b904953bb0d929eb87c 100644 (file)
@@ -131,14 +131,14 @@ class Redmine::ListFieldFormatTest < ActionView::TestCase
   def test_field_with_url_pattern_should_link_value
     field = IssueCustomField.new(:field_format => 'list', :url_pattern => 'http://localhost/%value%')
     formatted = field.format.formatted_value(self, field, 'foo', Issue.new, true)
-    assert_equal '<a href="http://localhost/foo">foo</a>', formatted
+    assert_equal '<a class="external" href="http://localhost/foo">foo</a>', formatted
     assert formatted.html_safe?
   end
 
   def test_field_with_url_pattern_and_multiple_values_should_link_values
     field = IssueCustomField.new(:field_format => 'list', :url_pattern => 'http://localhost/%value%')
     formatted = field.format.formatted_value(self, field, ['foo', 'bar'], Issue.new, true)
-    assert_equal '<a href="http://localhost/bar">bar</a>, <a href="http://localhost/foo">foo</a>', formatted
+    assert_equal '<a class="external" href="http://localhost/bar">bar</a>, <a class="external" href="http://localhost/foo">foo</a>', formatted
     assert formatted.html_safe?
   end
 
index 6fdb9b2fe922ee9254fefd3a5952275589c47486..e6572d8c694b4a4f8e20bad1f3cf6b4ddc5cf24b 100644 (file)
@@ -26,6 +26,6 @@ class Redmine::NumericFieldFormatTest < ActionView::TestCase
     custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "3")\r
 \r
     assert_equal 3, field.format.formatted_custom_value(self, custom_value, false)\r
-    assert_equal '<a href="http://foo/3">3</a>', field.format.formatted_custom_value(self, custom_value, true)\r
+    assert_equal '<a class="external" href="http://foo/3">3</a>', field.format.formatted_custom_value(self, custom_value, true)\r
   end\r
 end\r