From 1395d5686be12d90ebde42b1857b3d0d4b104340 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 22 Oct 2014 00:57:53 -0700 Subject: [PATCH] Optimize more URL#sanitize_url --- lib/jekyll/url.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/jekyll/url.rb b/lib/jekyll/url.rb index 310d9e43..964c619d 100644 --- a/lib/jekyll/url.rb +++ b/lib/jekyll/url.rb @@ -52,19 +52,19 @@ module Jekyll # Returns a sanitized String URL def sanitize_url(in_url) + url = in_url + # Remove all double slashes + .tr('//', '/') \ - # Remove all double slashes - url = in_url.gsub(/\/\//, "/") + # Remove every URL segment that consists solely of dots + .split('/').reject{ |part| part =~ /^\.+$/ }.join('/') \ - # Remove every URL segment that consists solely of dots - url = url.split('/').reject{ |part| part =~ /^\.+$/ }.join('/') + # Always add a leading slash + .gsub(/\A([^\/])/, '/\1') # Append a trailing slash to the URL if the unsanitized URL had one url += "/" if in_url =~ /\/$/ - # Always add a leading slash - url.gsub!(/\A([^\/])/, '/\1') - url end