From 0ed8e879d57e8a070ce9b02c71b5e78988f86ac6 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Mon, 13 Dec 2010 13:54:22 +0100 Subject: [PATCH] When reading inline templates, make sure to use binary encoding, avoiding to raise an exception for unknown byte sequences. --- lib/sinatra/base.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 70b30810cb..c38d230a3b 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -910,8 +910,10 @@ def inline_templates=(file=nil) file = (file.nil? || file == true) ? (caller_files.first || File.expand_path($0)) : file begin - app, data = - ::IO.read(file).gsub("\r\n", "\n").split(/^__END__$/, 2) + io = '1.9'.respond_to?(:encoding) ? + ::IO.read(file, nil, 0, :encoding => 'BINARY') : + ::IO.read(file) + app, data = io.gsub("\r\n", "\n").split(/^__END__$/, 2) rescue Errno::ENOENT app, data = nil end