]> source.dussan.org Git - redmine.git/commitdiff
Replaces use of Digest::MD5 / Digest::SHA1 with ActiveSupport::Digest (#35217).
authorMarius Balteanu <marius.balteanu@zitec.com>
Tue, 7 May 2024 18:36:46 +0000 (18:36 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Tue, 7 May 2024 18:36:46 +0000 (18:36 +0000)
Patch by Jens Krämer (@jkraemer).

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

app/controllers/repositories_controller.rb
app/models/attachment.rb
app/views/repositories/_dir_list_content.html.erb
lib/redmine/wiki_formatting.rb
lib/redmine/wiki_formatting/section_helper.rb
lib/redmine/wiki_formatting/textile/formatter.rb
test/functional/wiki_controller_test.rb
test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb
test/unit/lib/redmine/wiki_formatting/markdown_formatter_test.rb
test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb

index 2645ded4079fed4493c02aa9db8dfd069d0cd8ea..8deb35404687864b57c031d46fcaa85fec5bb0da 100644 (file)
@@ -279,7 +279,7 @@ class RepositoriesController < ApplicationController
         User.current.preference.save
       end
       @cache_key = "repositories/diff/#{@repository.id}/" +
-                      Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}")
+                      ActiveSupport::Digest.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}")
       unless read_fragment(@cache_key)
         @diff = @repository.diff(@path, @rev, @rev_to)
         (show_error_not_found; return) unless @diff
index c9054e903276807b0414a8e636f52a28d13f6fbf..59addf5281c9bf154119b043a41e803f4b62e988 100644 (file)
@@ -135,7 +135,7 @@ class Attachment < ApplicationRecord
   end
 
   # Copies the temporary file to its final location
-  # and computes its MD5 hash
+  # and computes its hash
   def files_to_final_location
     if @temp_file
       self.disk_directory = target_directory
@@ -559,7 +559,7 @@ class Attachment < ApplicationRecord
       if %r{^[a-zA-Z0-9_\.\-]*$}.match?(filename) && filename.length <= 50
         ascii = filename
       else
-        ascii = Digest::MD5.hexdigest(filename)
+        ascii = ActiveSupport::Digest.hexdigest(filename)
         # keep the extension if any
         ascii << $1 if filename =~ %r{(\.[a-zA-Z0-9]+)$}
       end
index ee68c1b7a5d47e2ec15ede8ac086766a9107ae55..396c7f6d0ff534d8a119ddd55c586401bf468dbe 100644 (file)
@@ -1,5 +1,5 @@
 <% @entries.each do |entry| %>
-<% tr_id = Digest::MD5.hexdigest(entry.path)
+<% tr_id = ActiveSupport::Digest.hexdigest(entry.path)
    depth = params[:depth].to_i %>
 <%  ent_path = Redmine::CodesetUtil.replace_invalid_utf8(entry.path)   %>
 <%  ent_name = Redmine::CodesetUtil.replace_invalid_utf8(entry.name)   %>
index 3486c74c615f342c3feb3d6f01daca1360abab54..cc68e9972ba598f47df9252eefed1dbecf7cce34 100644 (file)
@@ -18,7 +18,6 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 require_relative 'wiki_formatting/textile/redcloth3'
-require 'digest/md5'
 
 module Redmine
   module WikiFormatting
@@ -110,7 +109,7 @@ module Redmine
       # Returns a cache key for the given text +format+, +text+, +object+ and +attribute+ or nil if no caching should be done
       def cache_key_for(format, text, object, attribute)
         if object && attribute && !object.new_record? && format.present?
-          "formatted_text/#{format}/#{object.class.model_name.cache_key}/#{object.id}-#{attribute}-#{Digest::MD5.hexdigest text}"
+          "formatted_text/#{format}/#{object.class.model_name.cache_key}/#{object.id}-#{attribute}-#{ActiveSupport::Digest.hexdigest text}"
         end
       end
 
index 9221d990df79d16364282b4a7e64650e483ca73c..6f53a3f8e7f70c518d36f719d5c2112fe26ed95f 100644 (file)
@@ -22,13 +22,13 @@ module Redmine
     module SectionHelper
       def get_section(index)
         section = extract_sections(index)[1]
-        hash = Digest::MD5.hexdigest(section)
+        hash = ActiveSupport::Digest.hexdigest(section)
         return section, hash
       end
 
       def update_section(index, update, hash=nil)
         t = extract_sections(index)
-        if hash.present? && hash != Digest::MD5.hexdigest(t[1])
+        if hash.present? && hash != ActiveSupport::Digest.hexdigest(t[1])
           raise Redmine::WikiFormatting::StaleSectionError
         end
 
index 1cacfeed61c3b1dbb613b77d4b3606b9eb9261d8..35684a6c78ca69a6a2857303768333e86e1065fb 100644 (file)
@@ -17,8 +17,6 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-require 'digest/md5'
-
 module Redmine
   module WikiFormatting
     module Textile
index 215c9caf4f3fd022b6ec945de4d30eb92c20f53a..31dcf395d5c2f455717d73280a3e232943b89941 100644 (file)
@@ -677,7 +677,7 @@ class WikiControllerTest < Redmine::ControllerTest
               :version => 3
             },
             :section => 2,
-            :section_hash => Digest::MD5.hexdigest("wrong hash")
+            :section_hash => ActiveSupport::Digest.hexdigest("wrong hash")
           }
         end
       end
index 16bd8c972962366656deee5e9d812b921e187796..03376e34219defe128f0c3061d82452f336ac129 100644 (file)
@@ -292,7 +292,7 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase
       assert_kind_of Array, result
       assert_equal 2, result.size
       assert_equal expected, result.first, "section content did not match"
-      assert_equal Digest::MD5.hexdigest(expected), result.last, "section hash did not match"
+      assert_equal ActiveSupport::Digest.hexdigest(expected), result.last, "section hash did not match"
     end
   end
 end
index 75d3ff3659c70474f13b850d7d53b58d13fb1b79..012ec7ec92ef0fd2db8695bb89a559f024fc92dc 100644 (file)
@@ -349,6 +349,6 @@ class Redmine::WikiFormatting::MarkdownFormatterTest < ActionView::TestCase
     assert_kind_of Array, result
     assert_equal 2, result.size
     assert_equal expected, result.first, "section content did not match"
-    assert_equal Digest::MD5.hexdigest(expected), result.last, "section hash did not match"
+    assert_equal ActiveSupport::Digest.hexdigest(expected), result.last, "section hash did not match"
   end
 end
index cdbad2a552eea290424edd4e33fc84d3988cf8cf..32280cfdf0515eedd2116248d9736a7bb6fb7bb0 100644 (file)
@@ -19,7 +19,6 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 require_relative '../../../../test_helper'
-require 'digest/md5'
 
 class Redmine::WikiFormatting::TextileFormatterTest < ActionView::TestCase
   def setup
@@ -491,13 +490,13 @@ class Redmine::WikiFormatting::TextileFormatterTest < ActionView::TestCase
     assert_equal(
       [STR_WITHOUT_PRE[0], replacement, STR_WITHOUT_PRE[2..4]].flatten.join("\n\n"),
       @formatter.new(TEXT_WITHOUT_PRE).
-        update_section(2, replacement, Digest::MD5.hexdigest(STR_WITHOUT_PRE[1]))
+        update_section(2, replacement, ActiveSupport::Digest.hexdigest(STR_WITHOUT_PRE[1]))
     )
   end
 
   def test_update_section_with_wrong_hash_should_raise_an_error
     assert_raise Redmine::WikiFormatting::StaleSectionError do
-      @formatter.new(TEXT_WITHOUT_PRE).update_section(2, "New text", Digest::MD5.hexdigest("Old text"))
+      @formatter.new(TEXT_WITHOUT_PRE).update_section(2, "New text", ActiveSupport::Digest.hexdigest("Old text"))
     end
   end
 
@@ -809,6 +808,6 @@ class Redmine::WikiFormatting::TextileFormatterTest < ActionView::TestCase
     assert_kind_of Array, result
     assert_equal 2, result.size
     assert_equal expected, result.first, "section content did not match"
-    assert_equal Digest::MD5.hexdigest(expected), result.last, "section hash did not match"
+    assert_equal ActiveSupport::Digest.hexdigest(expected), result.last, "section hash did not match"
   end
 end