Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormicael.bergeron <micael.bergeron@solutionstlm.com>2017-09-05 20:16:08 +0300
committermicael.bergeron <micael.bergeron@solutionstlm.com>2017-09-06 16:01:53 +0300
commita6af5522d7cefaa7d08d28448b5059be07328a2f (patch)
tree3dc57ec3d7058a39e73ad3be5171a56debcb8849 /lib/gitlab/encoding_helper.rb
parentdbaed90c8d3dffb2dd970f1621f551dd322db5ee (diff)
renames ambiguous methods and add spec
Diffstat (limited to 'lib/gitlab/encoding_helper.rb')
-rw-r--r--lib/gitlab/encoding_helper.rb10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/gitlab/encoding_helper.rb b/lib/gitlab/encoding_helper.rb
index 8ac756a0b6a..c50417f4d4f 100644
--- a/lib/gitlab/encoding_helper.rb
+++ b/lib/gitlab/encoding_helper.rb
@@ -24,7 +24,7 @@ module Gitlab
# return message if message type is binary
detect = CharlockHolmes::EncodingDetector.detect(message)
- return message.force_encoding("BINARY") if all_binary?(message, detect)
+ return message.force_encoding("BINARY") if detect_binary?(message, detect)
if detect && detect[:encoding] && detect[:confidence] > ENCODING_CONFIDENCE_THRESHOLD
# force detected encoding if we have sufficient confidence.
@@ -38,17 +38,17 @@ module Gitlab
"--broken encoding: #{encoding}"
end
- def all_binary?(data, detect = nil)
+ def detect_binary?(data, detect = nil)
detect ||= CharlockHolmes::EncodingDetector.detect(data)
- detect && detect[:type] == :binary
+ detect && detect[:type] == :binary && detect[:confidence] == 100
end
- def libgit2_binary?(data)
+ def detect_libgit2_binary?(data)
# EncodingDetector checks the first 1024 * 1024 bytes for NUL byte, libgit2 checks
# only the first 8000 (https://github.com/libgit2/libgit2/blob/2ed855a9e8f9af211e7274021c2264e600c0f86b/src/filter.h#L15),
# which is what we use below to keep a consistent behavior.
detect = CharlockHolmes::EncodingDetector.new(8000).detect(data)
- all_binary?(data, detect)
+ detect && detect[:type] == :binary
end
def encode_utf8(message)