remove encode lib, clean all encoded area.

This commit is contained in:
Saito 2012-11-09 01:41:07 +08:00
parent 96211b01a8
commit f1ac2a616b
10 changed files with 10 additions and 73 deletions

View file

@ -1,41 +0,0 @@
# Patch Strings to enable detect_encoding! on views
require 'charlock_holmes/string'
module Gitlab
module Encode
extend self
def utf8 message
# return nil if message is nil
return nil unless message
message.force_encoding("utf-8")
# return message if message type is binary
detect = CharlockHolmes::EncodingDetector.detect(message)
return message if detect[:type] == :binary
# if message is utf-8 encoding, just return it
return message if message.valid_encoding?
# if message is not utf-8 encoding, convert it
if detect[:encoding]
message.force_encoding(detect[:encoding])
message.encode!("utf-8", detect[:encoding], undef: :replace, replace: "", invalid: :replace)
end
# ensure message encoding is utf8
message.valid_encoding? ? message : raise
# Prevent app from crash cause of encoding errors
rescue
encoding = detect ? detect[:encoding] : "unknown"
"--broken encoding: #{encoding}"
end
def detect_encoding message
return nil unless message
hash = CharlockHolmes::EncodingDetector.detect(message) rescue {}
return hash[:encoding] ? hash[:encoding] : nil
end
end
end

View file

@ -22,13 +22,13 @@ module Gitlab
h[:parents] = self.parents.collect do |p|
[p.id,0,0]
end
h[:author] = Gitlab::Encode.utf8(author.name)
h[:author] = author.name
h[:time] = time
h[:space] = space
h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil?
h[:id] = sha
h[:date] = date
h[:message] = escape_once(Gitlab::Encode.utf8(message))
h[:message] = escape_once(message)
h[:login] = author.email
h
end