From d070a77716f65fc9cbdef1aed91943959e9616e0 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Thu, 24 Dec 2015 15:07:20 -0500 Subject: [PATCH] url: fix issue with bad URL escaping when using Drop --- lib/jekyll/url.rb | 8 ++++++-- lib/jekyll/utils.rb | 13 +++++++------ test/test_url.rb | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/jekyll/url.rb b/lib/jekyll/url.rb index b338c23a..a001f44d 100644 --- a/lib/jekyll/url.rb +++ b/lib/jekyll/url.rb @@ -79,8 +79,12 @@ module Jekyll end def generate_url_from_drop(template) - template.gsub(/(:[a-z_]+)/) do |match| - @placeholders.public_send(match.sub(':', '')) + template.gsub(/:([a-z_]+)/) do |match| + if replacement = @placeholders.public_send(match.sub(':', '')) + self.class.escape_path replacement + else + ''.freeze + end end.gsub(/\/\//, '/') end diff --git a/lib/jekyll/utils.rb b/lib/jekyll/utils.rb index 94da8bd5..a2c6139d 100644 --- a/lib/jekyll/utils.rb +++ b/lib/jekyll/utils.rb @@ -174,13 +174,14 @@ module Jekyll SLUGIFY_PRETTY_REGEXP end - slug = string. - # Strip according to the mode - gsub(re, '-'). - # Remove leading/trailing hyphen - gsub(/^\-|\-$/i, '') + # Strip according to the mode + slug = string.gsub(re, '-') - cased ? slug : slug.downcase + # Remove leading/trailing hyphen + slug.gsub!(/^\-|\-$/i, '') + + slug.downcase! unless cased + slug end # Add an appropriate suffix to template so that it matches the specified diff --git a/test/test_url.rb b/test/test_url.rb index e4529be7..578e8962 100644 --- a/test/test_url.rb +++ b/test/test_url.rb @@ -54,5 +54,23 @@ class TestURL < JekyllUnitTest ).to_s end + should "handle UrlDrop as a placeholder in addition to a hash" do + site = fixture_site({ + "collections" => { + "methods" => { + "output" => true + } + }, + }) + site.read + doc = site.collections["methods"].docs.find do |doc| + doc.relative_path == "_methods/escape-+ #%20[].md" + end + assert_equal '/methods/escape-+-20/escape-20.html', URL.new( + :template => '/methods/:title/:name:output_ext', + :placeholders => doc.url_placeholders + ).to_s + end + end end