Escape filenames in regexes. Fixes #942.

This commit is contained in:
Ben Hollis 2013-08-15 22:03:32 -07:00
parent a3e030e846
commit f92ae94728
3 changed files with 3 additions and 3 deletions

View file

@ -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

View file

@ -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)

View file

@ -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