Skip to content

Instantly share code, notes, and snippets.

@aoleg94
Created December 26, 2018 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aoleg94/702a6633b4c202c0e0851cbe4d58d7f2 to your computer and use it in GitHub Desktop.
Save aoleg94/702a6633b4c202c0e0851cbe4d58d7f2 to your computer and use it in GitHub Desktop.
Gitlab CP1251 patch
cd /opt/gitlab && patch -p2 < this-patch
--- opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/gitlab-grit-2.8.2/lib/grit_ext.rb.orig 2018-12-22 01:24:08.000000000 +0500
+++ opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/gitlab-grit-2.8.2/lib/grit_ext.rb 2018-12-26 13:21:46.792000000 +0500
@@ -22,7 +22,8 @@
# encoding message to detect encoding
if detect && detect[:encoding]
- message.force_encoding(detect[:encoding])
+ message.force_encoding("windows-1251")
+ message.encode("utf-8", "windows-1251", undef: :replace, replace: "", invalid: :replace)
end
# encode and clean the bad chars
--- opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/encoding_helper.rb.orig 2018-12-22 01:24:14.000000000 +0500
+++ opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/encoding_helper.rb 2018-12-26 13:20:10.772000000 +0500
@@ -23,9 +23,10 @@
detect = CharlockHolmes::EncodingDetector.detect(message)
return message.force_encoding("BINARY") if detect_binary?(message, detect)
- if detect && detect[:encoding] && detect[:confidence] > ENCODING_CONFIDENCE_THRESHOLD
+ if detect && detect[:encoding]
# force detected encoding if we have sufficient confidence.
- message.force_encoding(detect[:encoding])
+ message.force_encoding("windows-1251")
+ message.encode("utf-8", "windows-1251", undef: :replace, replace: "", invalid: :replace)
end
# encode and clean the bad chars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment