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

View file

@ -56,7 +56,7 @@ css:
.row
.span12
div id="editor" style="width: 100%; height: 600px; position: relative;"
#{@file_data}
== encoding_fix @file_data
.row