diff --git a/lib/jekyll/url.rb b/lib/jekyll/url.rb index 6bed8d57..60c96507 100644 --- a/lib/jekyll/url.rb +++ b/lib/jekyll/url.rb @@ -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 diff --git a/test/test_url.rb b/test/test_url.rb index 15f989d8..b66e2f86 100644 --- a/test/test_url.rb +++ b/test/test_url.rb @@ -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