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
This commit is contained in:
parent
71a20bb3ee
commit
8a8ee768ac
2 changed files with 18 additions and 0 deletions
|
@ -58,6 +58,8 @@ module Middleman
|
||||||
def step_through_extensions(path)
|
def step_through_extensions(path)
|
||||||
while ::Middleman::Util.tilt_class(path)
|
while ::Middleman::Util.tilt_class(path)
|
||||||
ext = ::File.extname(path)
|
ext = ::File.extname(path)
|
||||||
|
break if ext.empty?
|
||||||
|
|
||||||
yield ext if block_given?
|
yield ext if block_given?
|
||||||
|
|
||||||
# Strip templating extensions as long as Tilt knows them
|
# Strip templating extensions as long as Tilt knows them
|
||||||
|
|
|
@ -204,4 +204,20 @@ describe Middleman::Util do
|
||||||
expect(related).to include File.expand_path("source/stylesheets/include2.css.scss")
|
expect(related).to include File.expand_path("source/stylesheets/include2.css.scss")
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue