diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-03-15 17:42:31 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-03-15 18:52:22 +0300 |
commit | 3b1d5a1dffa35746d3619b90f3e82f8437e38c91 (patch) | |
tree | e38174737f589e350a6a7359d953b7d60fad9cfe /app | |
parent | 60df262c38d7c235b483cc1c4beb12f793e0e58a (diff) |
Prevent gitlab-shell character encoding issues by receiving its changes as raw data.
Diffstat (limited to 'app')
-rw-r--r-- | app/workers/post_receive.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/app/workers/post_receive.rb b/app/workers/post_receive.rb index ecc6c8e53a3..0c3ee6ba4ff 100644 --- a/app/workers/post_receive.rb +++ b/app/workers/post_receive.rb @@ -21,7 +21,9 @@ class PostReceive return false end - changes = changes.lines if changes.kind_of?(String) + changes = Base64.decode64(changes) unless changes.include?(" ") + changes = utf8_encode_changes(changes) + changes = changes.lines changes.each do |change| oldrev, newrev, ref = change.strip.split(' ') @@ -41,6 +43,19 @@ class PostReceive end end + def utf8_encode_changes(changes) + changes = changes.dup + + changes.force_encoding("UTF-8") + return changes if changes.valid_encoding? + + # Convert non-UTF-8 branch/tag names to UTF-8 so they can be dumped as JSON. + detection = CharlockHolmes::EncodingDetector.detect(changes) + return changes unless detection && detection[:encoding] + + CharlockHolmes::Converter.convert(changes, detection[:encoding], 'UTF-8') + end + def log(message) Gitlab::GitLogger.error("POST-RECEIVE: #{message}") end |