Skip to content

Commit

Permalink
Replaces use of Digest::MD5 / Digest::SHA1 with ActiveSupport::Digest…
Browse files Browse the repository at this point in the history
… (#35217).

Patch by Jens Krämer (@jkraemer).

git-svn-id: https://svn.redmine.org/redmine/trunk@22816 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
marius-balteanu committed May 7, 2024
1 parent 9ef1cdd commit b4bfb6b
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/controllers/repositories_controller.rb
Expand Up @@ -279,7 +279,7 @@ def diff
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
Expand Down
4 changes: 2 additions & 2 deletions app/models/attachment.rb
Expand Up @@ -135,7 +135,7 @@ def filename=(arg)
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
Expand Down Expand Up @@ -559,7 +559,7 @@ def create_diskfile(filename, directory=nil, &block)
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
Expand Down
2 changes: 1 addition & 1 deletion app/views/repositories/_dir_list_content.html.erb
@@ -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) %>
Expand Down
3 changes: 1 addition & 2 deletions lib/redmine/wiki_formatting.rb
Expand Up @@ -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
Expand Down Expand Up @@ -110,7 +109,7 @@ def supports_section_edit?
# 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

Expand Down
4 changes: 2 additions & 2 deletions lib/redmine/wiki_formatting/section_helper.rb
Expand Up @@ -22,13 +22,13 @@ module WikiFormatting
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

Expand Down
2 changes: 0 additions & 2 deletions lib/redmine/wiki_formatting/textile/formatter.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/functional/wiki_controller_test.rb
Expand Up @@ -677,7 +677,7 @@ def test_update_section_should_not_allow_stale_section_update
:version => 3
},
:section => 2,
:section_hash => Digest::MD5.hexdigest("wrong hash")
:section_hash => ActiveSupport::Digest.hexdigest("wrong hash")
}
end
end
Expand Down
Expand Up @@ -292,7 +292,7 @@ def assert_section_with_hash(expected, text, index)
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
Expand Up @@ -349,6 +349,6 @@ def assert_section_with_hash(expected, text, index)
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
Expand Up @@ -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
Expand Down Expand Up @@ -491,13 +490,13 @@ def test_update_section_with_hash_should_update_the_requested_section
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

Expand Down Expand Up @@ -809,6 +808,6 @@ def assert_section_with_hash(expected, text, index)
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

0 comments on commit b4bfb6b

Please sign in to comment.