Fixed encoding problems with plain/text blobs being sent without charset.
This commit is contained in:
parent
cc8369144d
commit
eb5749ed39
|
@ -1,4 +1,5 @@
|
||||||
class RefsController < ApplicationController
|
class RefsController < ApplicationController
|
||||||
|
include Gitlabhq::Encode
|
||||||
before_filter :project
|
before_filter :project
|
||||||
|
|
||||||
# Authorize
|
# Authorize
|
||||||
|
@ -49,9 +50,16 @@ class RefsController < ApplicationController
|
||||||
|
|
||||||
def blob
|
def blob
|
||||||
if @tree.is_blob?
|
if @tree.is_blob?
|
||||||
|
if @tree.text?
|
||||||
|
encoding = detect_encoding(@tree.data)
|
||||||
|
mime_type = encoding ? "text/plain; charset=#{encoding}" : "text/plain"
|
||||||
|
else
|
||||||
|
mime_type = @tree.mime_type
|
||||||
|
end
|
||||||
|
|
||||||
send_data(
|
send_data(
|
||||||
@tree.data,
|
@tree.data,
|
||||||
:type => @tree.text? ? "text/plain" : @tree.mime_type,
|
:type => mime_type,
|
||||||
:disposition => 'inline',
|
:disposition => 'inline',
|
||||||
:filename => @tree.name
|
:filename => @tree.name
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,9 +5,9 @@ module Gitlabhq
|
||||||
def utf8 message
|
def utf8 message
|
||||||
return nil unless message
|
return nil unless message
|
||||||
|
|
||||||
hash = CharlockHolmes::EncodingDetector.detect(message) rescue {}
|
encoding = detect_encoding(message)
|
||||||
if hash[:encoding]
|
if encoding
|
||||||
CharlockHolmes::Converter.convert(message, hash[:encoding], 'UTF-8')
|
CharlockHolmes::Converter.convert(message, encoding, 'UTF-8')
|
||||||
else
|
else
|
||||||
message
|
message
|
||||||
end.force_encoding("utf-8")
|
end.force_encoding("utf-8")
|
||||||
|
@ -16,5 +16,12 @@ module Gitlabhq
|
||||||
rescue
|
rescue
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def detect_encoding message
|
||||||
|
return nil unless message
|
||||||
|
|
||||||
|
hash = CharlockHolmes::EncodingDetector.detect(message) rescue {}
|
||||||
|
return hash[:encoding] ? hash[:encoding] : nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue