drop down to binary if UTF fails, don't conduct any replacing of characters

This commit is contained in:
Kyle Drake 2013-07-23 15:54:48 +02:00
parent 4d06265c9c
commit 27bcc479d5
2 changed files with 10 additions and 1 deletions

9
app.rb
View file

@ -579,3 +579,12 @@ end
def template_site_title(username)
"#{username.capitalize}#{username[username.length-1] == 's' ? "'" : "'s"} Site"
end
def encoding_fix(file)
begin
Rack::Utils.escape_html file
rescue ArgumentError => e
return Rack::Utils.escape_html(file.force_encoding('BINARY')) if e.message =~ /invalid byte sequence in UTF-8/
fail
end
end