diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /lib/gitlab/blob_helper.rb | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) | |
download | gitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'lib/gitlab/blob_helper.rb')
-rw-r--r-- | lib/gitlab/blob_helper.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/gitlab/blob_helper.rb b/lib/gitlab/blob_helper.rb index fc579ad8d2a..57d632afd74 100644 --- a/lib/gitlab/blob_helper.rb +++ b/lib/gitlab/blob_helper.rb @@ -3,6 +3,8 @@ # This has been extracted from https://github.com/github/linguist/blob/master/lib/linguist/blob_helper.rb module Gitlab module BlobHelper + include Gitlab::Utils::StrongMemoize + def extname File.extname(name.to_s) end @@ -120,8 +122,18 @@ module Gitlab end def encoded_newlines_re - @encoded_newlines_re ||= - Regexp.union(["\r\n", "\r", "\n"].map { |nl| nl.encode(ruby_encoding, "ASCII-8BIT").force_encoding(data.encoding) }) + strong_memoize(:encoded_newlines_re) do + newlines = ["\r\n", "\r", "\n"] + data_encoding = data&.encoding + + if ruby_encoding && data_encoding + newlines.map! do |nl| + nl.encode(ruby_encoding, "ASCII-8BIT").force_encoding(data_encoding) + end + end + + Regexp.union(newlines) + end end def ruby_encoding |