Skip to content

Commit

Permalink
When reading inline templates, make sure to use
Browse files Browse the repository at this point in the history
binary encoding, avoiding to raise an exception
for unknown byte sequences.
  • Loading branch information
rkh committed Dec 14, 2010
1 parent 5b941ab commit 0ed8e87
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/sinatra/base.rb
Expand Up @@ -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
Expand Down

0 comments on commit 0ed8e87

Please sign in to comment.