From eb2423c6c43dc858b5a8c081ad55aa2549c0a401 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sun, 10 May 2020 20:32:36 +0530 Subject: [PATCH] Optimize path sanitization of default front matter (#8154) Merge pull request 8154 --- 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