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