Optimize path sanitization of default front matter (#8154)

Merge pull request 8154
This commit is contained in:
Ashwin Maroli 2020-05-10 20:32:36 +05:30 committed by GitHub
parent dc8f57d412
commit eb2423c6c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 5 deletions

View File

@ -226,15 +226,14 @@ module Jekyll
end.compact
end
# Sanitizes the given path by removing a leading and adding a trailing slash
SANITIZATION_REGEX = %r!\A/|(?<=[^/])\z!.freeze
# Sanitizes the given path by removing a leading slash
def sanitize_path(path)
if path.nil? || path.empty?
""
elsif path.start_with?("/")
path.gsub(%r!\A/|(?<=[^/])\z!, "")
else
path.gsub(SANITIZATION_REGEX, "")
path
end
end
end