Merge pull request #3325 from imathis/generate-url

This commit is contained in:
Alfred Xing 2015-01-24 11:21:51 -08:00
commit 31b03e9b86
2 changed files with 13 additions and 1 deletions

View File

@ -61,7 +61,12 @@ module Jekyll
def generate_url(template)
@placeholders.inject(template) do |result, token|
break result if result.index(':').nil?
result.gsub(/:#{token.first}/, self.class.escape_path(token.last))
if token.last.nil?
# Remove leading '/' to avoid generating urls with `//`
result.gsub(/\/:#{token.first}/, '')
else
result.gsub(/:#{token.first}/, self.class.escape_path(token.last))
end
end
end

View File

@ -47,5 +47,12 @@ class TestURL < Test::Unit::TestCase
).to_s
end
should "handle nil values for keys in the template" do
assert_equal '/foo/bar/', URL.new(
:template => "/:x/:y/:z/",
:placeholders => {:x => "foo", :y => "bar", :z => nil}
).to_s
end
end
end