Skip to content

Commit

Permalink
[api] avoid a crash on non UTF-8 files
Browse files Browse the repository at this point in the history
  • Loading branch information
coolo committed Dec 6, 2013
1 parent a4465b3 commit b686cca
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/api/app/helpers/webui/webui_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,11 @@ def elide_two(text1, text2, overall_length = 40, mode = :middle)
end

def force_utf8_and_transform_nonprintables(text)
text.force_encoding('UTF-8')
unless text.valid_encoding?
text = 'The file you look at is not valid UTF-8 text. Please convert the file.'
end
# Ged rid of stuff that shouldn't be part of PCDATA:
text.force_encoding('UTF-8')
return text.gsub(/([^a-zA-Z0-9&;<>\/\n \t()])/) do
if $1[0].getbyte(0) < 32
''
Expand Down

0 comments on commit b686cca

Please sign in to comment.