Commit eb5749ed392aa375ee6c50e9f6c9a5aabc11820b
1 parent
cc836914
Exists in
master
and in
4 other branches
Fixed encoding problems with plain/text blobs being sent without charset.
Showing
2 changed files
with
19 additions
and
4 deletions
Show diff stats
app/controllers/refs_controller.rb
| 1 | 1 | class RefsController < ApplicationController |
| 2 | + include Gitlabhq::Encode | |
| 2 | 3 | before_filter :project |
| 3 | 4 | |
| 4 | 5 | # Authorize |
| ... | ... | @@ -49,9 +50,16 @@ class RefsController < ApplicationController |
| 49 | 50 | |
| 50 | 51 | def blob |
| 51 | 52 | if @tree.is_blob? |
| 53 | + if @tree.text? | |
| 54 | + encoding = detect_encoding(@tree.data) | |
| 55 | + mime_type = encoding ? "text/plain; charset=#{encoding}" : "text/plain" | |
| 56 | + else | |
| 57 | + mime_type = @tree.mime_type | |
| 58 | + end | |
| 59 | + | |
| 52 | 60 | send_data( |
| 53 | 61 | @tree.data, |
| 54 | - :type => @tree.text? ? "text/plain" : @tree.mime_type, | |
| 62 | + :type => mime_type, | |
| 55 | 63 | :disposition => 'inline', |
| 56 | 64 | :filename => @tree.name |
| 57 | 65 | ) | ... | ... |
lib/gitlabhq/encode.rb
| ... | ... | @@ -5,9 +5,9 @@ module Gitlabhq |
| 5 | 5 | def utf8 message |
| 6 | 6 | return nil unless message |
| 7 | 7 | |
| 8 | - hash = CharlockHolmes::EncodingDetector.detect(message) rescue {} | |
| 9 | - if hash[:encoding] | |
| 10 | - CharlockHolmes::Converter.convert(message, hash[:encoding], 'UTF-8') | |
| 8 | + encoding = detect_encoding(message) | |
| 9 | + if encoding | |
| 10 | + CharlockHolmes::Converter.convert(message, encoding, 'UTF-8') | |
| 11 | 11 | else |
| 12 | 12 | message |
| 13 | 13 | end.force_encoding("utf-8") |
| ... | ... | @@ -16,5 +16,12 @@ module Gitlabhq |
| 16 | 16 | rescue |
| 17 | 17 | "" |
| 18 | 18 | end |
| 19 | + | |
| 20 | + def detect_encoding message | |
| 21 | + return nil unless message | |
| 22 | + | |
| 23 | + hash = CharlockHolmes::EncodingDetector.detect(message) rescue {} | |
| 24 | + return hash[:encoding] ? hash[:encoding] : nil | |
| 25 | + end | |
| 19 | 26 | end |
| 20 | 27 | end | ... | ... |