Fix/issue 1889 (#1892)

* Add regression test for infinite loop issue in Util::step_through_extensions (#1889)

* Prevent infinite loop when encountering files where base filename is a possible templating engine
feature/pipeline
Nick Giancola 2016-04-25 09:50:51 -07:00 committed by Thomas Reynolds
parent 71a20bb3ee
commit 8a8ee768ac
2 changed files with 18 additions and 0 deletions

View File

@ -58,6 +58,8 @@ module Middleman
def step_through_extensions(path)
while ::Middleman::Util.tilt_class(path)
ext = ::File.extname(path)
break if ext.empty?
yield ext if block_given?
# Strip templating extensions as long as Tilt knows them

View File

@ -204,4 +204,20 @@ describe Middleman::Util do
expect(related).to include File.expand_path("source/stylesheets/include2.css.scss")
end
end
describe "::step_through_extensions" do
it "returns the base name after templating engine extensions are removed" do
result = Middleman::Util.step_through_extensions('my_file.html.haml.erb')
expect(result).to eq 'my_file.html'
end
it "does not loop infinitely when file name is a possible templating engine" do
expect do
Timeout::timeout(0.5) do
result = Middleman::Util.step_through_extensions("markdown.scss")
expect(result).to eq "markdown"
end
end.not_to raise_error
end
end
end