url: fix issue with bad URL escaping when using Drop

This commit is contained in:
Parker Moore 2015-12-24 15:07:20 -05:00
parent bff1726a5a
commit d070a77716
3 changed files with 31 additions and 8 deletions

View File

@ -79,8 +79,12 @@ module Jekyll
end end
def generate_url_from_drop(template) def generate_url_from_drop(template)
template.gsub(/(:[a-z_]+)/) do |match| template.gsub(/:([a-z_]+)/) do |match|
@placeholders.public_send(match.sub(':', '')) if replacement = @placeholders.public_send(match.sub(':', ''))
self.class.escape_path replacement
else
''.freeze
end
end.gsub(/\/\//, '/') end.gsub(/\/\//, '/')
end end

View File

@ -174,13 +174,14 @@ module Jekyll
SLUGIFY_PRETTY_REGEXP SLUGIFY_PRETTY_REGEXP
end end
slug = string. # Strip according to the mode
# Strip according to the mode slug = string.gsub(re, '-')
gsub(re, '-').
# Remove leading/trailing hyphen
gsub(/^\-|\-$/i, '')
cased ? slug : slug.downcase # Remove leading/trailing hyphen
slug.gsub!(/^\-|\-$/i, '')
slug.downcase! unless cased
slug
end end
# Add an appropriate suffix to template so that it matches the specified # Add an appropriate suffix to template so that it matches the specified

View File

@ -54,5 +54,23 @@ class TestURL < JekyllUnitTest
).to_s ).to_s
end 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
end end