Change regex to sanitize and normalize filenames passed to LiquidRenderer (#6610)
Merge pull request 6610
This commit is contained in:
parent
1aae0bcc3a
commit
e1b64f9afd
|
@ -5,6 +5,11 @@ require_relative "liquid_renderer/table"
|
|||
|
||||
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 @@ module Jekyll
|
|||
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 @@ module Jekyll
|
|||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue