diff --git a/app.rb b/app.rb index ef0c94ea..a203fe99 100644 --- a/app.rb +++ b/app.rb @@ -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 diff --git a/views/site_files/text_editor.slim b/views/site_files/text_editor.slim index 5b2e4f8e..468352c5 100644 --- a/views/site_files/text_editor.slim +++ b/views/site_files/text_editor.slim @@ -56,7 +56,7 @@ css: .row .span12 div id="editor" style="width: 100%; height: 600px; position: relative;" - #{@file_data} + == encoding_fix @file_data .row