diff --git a/middleman-core/lib/middleman-core/core_extensions/front_matter.rb b/middleman-core/lib/middleman-core/core_extensions/front_matter.rb index fdeadd1c..f1b203a5 100644 --- a/middleman-core/lib/middleman-core/core_extensions/front_matter.rb +++ b/middleman-core/lib/middleman-core/core_extensions/front_matter.rb @@ -196,7 +196,7 @@ module Middleman::CoreExtensions end def normalize_path(path) - path.sub(%r{^#{app.source_dir}\/}, "") + path.sub(%r{^#{Regexp.escape(app.source_dir)}\/}, "") end end end diff --git a/middleman-core/lib/middleman-core/core_extensions/rendering.rb b/middleman-core/lib/middleman-core/core_extensions/rendering.rb index b26b8444..4db4983c 100644 --- a/middleman-core/lib/middleman-core/core_extensions/rendering.rb +++ b/middleman-core/lib/middleman-core/core_extensions/rendering.rb @@ -191,7 +191,7 @@ module Middleman engine = File.extname(resource.source_file)[1..-1].to_sym # Look for partials relative to the current path - relative_dir = File.join(current_dir.sub(%r{^#{self.source_dir}/?}, ""), data) + relative_dir = File.join(current_dir.sub(%r{^#{Regexp.escape(self.source_dir)}/?}, ""), data) # Try to use the current engine first found_partial, found_engine = resolve_template(relative_dir, :preferred_engine => engine, :try_without_underscore => true) diff --git a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb index 1a584da2..b0353ab3 100644 --- a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb +++ b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb @@ -124,7 +124,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension # If the basename of the request as no extension, assume we are serving a # directory and join index_file to the path. path = File.join(asset_dir, current_path) - path = path.sub(/#{File.extname(path)}$/, ".#{asset_ext}") + path = path.sub(/#{Regexp.escape(File.extname(path))}$/, ".#{asset_ext}") yield path if sitemap.find_resource_by_path(path) end