diff --git a/middleman-core/lib/middleman-core/util/files.rb b/middleman-core/lib/middleman-core/util/files.rb index e57179a4..3d185cea 100644 --- a/middleman-core/lib/middleman-core/util/files.rb +++ b/middleman-core/lib/middleman-core/util/files.rb @@ -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 diff --git a/middleman-core/spec/middleman-core/util_spec.rb b/middleman-core/spec/middleman-core/util_spec.rb index 8385889b..ea9bbd88 100644 --- a/middleman-core/spec/middleman-core/util_spec.rb +++ b/middleman-core/spec/middleman-core/util_spec.rb @@ -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