Merge pull request #3325 from imathis/generate-url
This commit is contained in:
commit
31b03e9b86
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue