From 27bcc479d5c351659defe4de3d7c79efdc704123 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Tue, 23 Jul 2013 15:54:48 +0200 Subject: [PATCH] drop down to binary if UTF fails, don't conduct any replacing of characters --- app.rb | 9 +++++++++ views/site_files/text_editor.slim | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) 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