mirror of
https://github.com/jekyll/jekyll.git
synced 2026-04-06 03:01:43 -04:00
Merge pull request #3325 from imathis/generate-url
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user