From 0066e0d11066f602b81948c83a9df04d793379c4 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sun, 3 May 2020 12:39:35 +0530 Subject: [PATCH] Optimize path sanitization of default front matter --- lib/jekyll/frontmatter_defaults.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/jekyll/frontmatter_defaults.rb b/lib/jekyll/frontmatter_defaults.rb index a7d7975cf84..a8442f510c3 100644 --- a/lib/jekyll/frontmatter_defaults.rb +++ b/lib/jekyll/frontmatter_defaults.rb @@ -226,15 +226,14 @@ def valid_sets 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