url: fix issue with bad URL escaping when using Drop
This commit is contained in:
parent
bff1726a5a
commit
d070a77716
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue