From 589919d58a518f53edcbac3ce5a7a8b00fa9096e Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Sun, 18 Jan 2015 08:31:14 -0600 Subject: [PATCH 1/3] Strip slashes on nil url tokens --- lib/jekyll/url.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 From 382049d558b49ea60e308eab345ec942432866e2 Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Sun, 18 Jan 2015 15:51:21 -0600 Subject: [PATCH 2/3] Added a unit test for nil value in permalink template keys --- test/test_url.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/test_url.rb b/test/test_url.rb index 15f989d8..ea11fb09 100644 --- a/test/test_url.rb +++ b/test/test_url.rb @@ -47,5 +47,13 @@ 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 => "/baz", + :permalink => "/:x/:y/:z/", + :placeholders => {:x => "foo", :y => "bar", :z => nil} + ).to_s + end + end end From 3d60299ea97f82558d3b69ac649771f162519298 Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Sun, 18 Jan 2015 23:03:27 -0600 Subject: [PATCH 3/3] Test updates: Removed permalink config, updated template --- test/test_url.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test_url.rb b/test/test_url.rb index ea11fb09..b66e2f86 100644 --- a/test/test_url.rb +++ b/test/test_url.rb @@ -49,8 +49,7 @@ class TestURL < Test::Unit::TestCase should "handle nil values for keys in the template" do assert_equal '/foo/bar/', URL.new( - :template => "/baz", - :permalink => "/:x/:y/:z/", + :template => "/:x/:y/:z/", :placeholders => {:x => "foo", :y => "bar", :z => nil} ).to_s end