Optimize more URL#sanitize_url

This commit is contained in:
Parker Moore 2014-10-22 00:57:53 -07:00
parent 3227c4ecea
commit 1395d5686b
1 changed files with 7 additions and 7 deletions

View File

@ -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