diff --git a/lib/jekyll/url.rb b/lib/jekyll/url.rb index 6b812a2e..3c4a0091 100644 --- a/lib/jekyll/url.rb +++ b/lib/jekyll/url.rb @@ -94,7 +94,8 @@ module Jekyll def generate_url_from_drop(template) template.gsub(%r!:([a-z_]+)!) do |match| - pool = possible_keys(match.sub(":", "")) + name = Regexp.last_match(1) + pool = name.end_with?("_") ? [name, name.chomp!("_")] : [name] winner = pool.find { |key| @placeholders.key?(key) } if winner.nil? @@ -107,15 +108,17 @@ module Jekyll value = "" if value.nil? replacement = self.class.escape_path(value) - match.sub(":#{winner}", replacement) - end.squeeze("/") + match.sub!(":#{winner}", replacement) + end end # Returns a sanitized String URL, stripping "../../" and multiples of "/", # as well as the beginning "/" so we can enforce and ensure it. - def sanitize_url(str) - "/#{str}".gsub("..", "/").gsub("./", "").squeeze("/") + "/#{str}".gsub("..", "/").tap do |result| + result.gsub!("./", "") + result.squeeze!("/") + end end # Escapes a path to be a valid URL path segment