From 64d852ea6f30ca4264f329415426d6cd2ebc7ae6 Mon Sep 17 00:00:00 2001 From: Yoji Shidara Date: Fri, 17 Apr 2009 14:17:15 +0200 Subject: [PATCH] Better handling of in file templates `__END__` in the middle of lines should not be recognized as the end of the ruby script. Ruby only accepts the line just contain `__END__`. Beginning/tailing whitespaces are not allowed. Signed-off-by: Simon Rozet --- lib/sinatra/base.rb | 2 +- test/templates_test.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 1c1c1b3d..c6327533 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -637,7 +637,7 @@ module Sinatra file ||= caller_files.first begin - data = ::IO.read(file).split('__END__')[1] + data = ::IO.read(file).split(/^__END__$/)[1] rescue data = nil end diff --git a/test/templates_test.rb b/test/templates_test.rb index 25db7630..2958ef0e 100644 --- a/test/templates_test.rb +++ b/test/templates_test.rb @@ -87,6 +87,8 @@ class TemplatesTest < Test::Unit::TestCase end end +# __END__ : this is not the real end of the script. + __END__ @@ foo