]> source.dussan.org Git - redmine.git/commitdiff
Add guard clause to time_tag method to handle nil time (#38139).
authorGo MAEDA <maeda@farend.jp>
Mon, 2 Jan 2023 06:56:47 +0000 (06:56 +0000)
committerGo MAEDA <maeda@farend.jp>
Mon, 2 Jan 2023 06:56:47 +0000 (06:56 +0000)
Patch by Go MAEDA.

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

app/helpers/application_helper.rb
test/helpers/application_helper_test.rb

index e599cc32ecca8a7536e6b065645b6a0ff218882f..a4bf27e576d9cd6f69c6fcdbb7902751b5470bc1 100644 (file)
@@ -694,6 +694,8 @@ module ApplicationHelper
   end
 
   def time_tag(time)
+    return if time.nil?
+
     text = distance_of_time_in_words(Time.now, time)
     if @project
       link_to(text,
index bb6b373906aa7423e8d7155a1527082639e2bbe8..cf7c4ff3a4a49763137bd7425331f2ce69496191 100644 (file)
@@ -2211,6 +2211,22 @@ class ApplicationHelperTest < Redmine::HelperTest
     end
   end
 
+  def test_time_tag
+    user = User.find(1)
+    user.pref.update(time_zone: 'UTC')
+    User.current = user
+
+    assert_nil time_tag(nil)
+    with_locale 'en' do
+      travel_to Time.zone.parse('2022-12-30T01:00:00Z') do
+        assert_equal "<abbr title=\"12/28/2022 01:00 AM\">2 days</abbr>", time_tag(2.days.ago)
+
+        @project = Project.find(1)
+        assert_equal "<a title=\"12/28/2022 01:00 AM\" href=\"/projects/ecookbook/activity?from=2022-12-28\">2 days</a>", time_tag(2.days.ago)
+      end
+    end
+  end
+
   private
 
   def wiki_links_with_special_characters