diff --git a/lib/gitlab/backend/grack_auth.rb b/lib/gitlab/backend/grack_auth.rb
index 6d87df17e757461ce897252945d9a20e0ba65385..6a411aabcc63e4b44a67716fe7485719559ed2af 100644
--- a/lib/gitlab/backend/grack_auth.rb
+++ b/lib/gitlab/backend/grack_auth.rb
@@ -109,11 +109,9 @@ def current_ref
       else
         input = @request.body.read
       end
-      # force utf-8 encoding
-      input.encode!('UTF-8', 'UTF-8', invalid: :replace, undef: :replace, replace: '')
       # Need to reset seek point
       @request.body.rewind
-      /refs\/heads\/([\w\.-]+)/.match(input).to_a.last
+      /refs\/heads\/([\w\.-]+)/n.match(input.force_encoding('ascii-8bit')).to_a.last
     end
 
     def project