Skip to content

Commit 64d852e

Browse files
Yoji Shidarartomayko
authored andcommitted
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 <simon@rozet.name>
1 parent b88c0f5 commit 64d852e

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/sinatra/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ def use_in_file_templates!(file=nil)
637637
file ||= caller_files.first
638638

639639
begin
640-
data = ::IO.read(file).split('__END__')[1]
640+
data = ::IO.read(file).split(/^__END__$/)[1]
641641
rescue
642642
data = nil
643643
end

test/templates_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def with_default_layout
8787
end
8888
end
8989

90+
# __END__ : this is not the real end of the script.
91+
9092
__END__
9193

9294
@@ foo

0 commit comments

Comments
 (0)