Permalink
Browse files

Change regex to sanitize and normalize filenames passed to LiquidRend…

…erer (#6610)

Merge pull request 6610
  • Loading branch information...
ashmaroli authored and jekyllbot committed Mar 10, 2018
1 parent 1aae0bc commit e1b64f9afd8391b9aeaea6a3b00700a8851585d1
Showing with 18 additions and 6 deletions.
  1. +17 −5 lib/jekyll/liquid_renderer.rb
  2. +1 −1 script/default-site
@@ -5,6 +5,11 @@
module Jekyll
class LiquidRenderer
extend Forwardable
def_delegator :@site, :in_source_dir, :source_dir
def_delegator :@site, :in_theme_dir, :theme_dir
def initialize(site)
@site = site
Liquid::Template.error_mode = @site.config["liquid"]["error_mode"].to_sym
@@ -16,11 +21,13 @@ def reset
end
def file(filename)
filename = @site.in_source_dir(filename).sub(
%r!\A#{Regexp.escape(@site.source)}/!,
""
)
filename.match(filename_regex)
filename =
if Regexp.last_match(1) == theme_dir("")
::File.join(Regexp.last_match(1).split("/")[-1], Regexp.last_match(2))
else
Regexp.last_match(2)
end
LiquidRenderer::File.new(self, filename).tap do
@stats[filename] ||= new_profile_hash
@stats[filename][:count] += 1
@@ -44,6 +51,11 @@ def self.format_error(e, path)
end
private
def filename_regex
%r!\A(#{source_dir}/|#{theme_dir}/|\W*)(.*)!oi
end
def new_profile_hash
Hash.new { |hash, key| hash[key] = 0 }
end
View
@@ -16,5 +16,5 @@ ruby -e "contents = File.read('Gemfile'); File.write('Gemfile', contents.sub(/ge
echo "$0: installing default site dependencies"
BUNDLE_GEMFILE=Gemfile bundle install
echo "$0: building the default site"
BUNDLE_GEMFILE=Gemfile bundle exec jekyll build --verbose
BUNDLE_GEMFILE=Gemfile bundle exec jekyll build --verbose --profile
popd

0 comments on commit e1b64f9

Please sign in to comment.