From 4bcece18ae88a5f32906939418b0b7121263e73a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Arild=20M=C3=A6land?= Date: Mon, 27 Apr 2009 13:42:24 +0200 Subject: [PATCH] Issue 7: CGI escape post titles Signed-off-by: Nick Quaranto --- lib/jekyll/post.rb | 5 +++-- test/source/_posts/2009-03-12-hash-#1.markdown | 6 ++++++ test/test_post.rb | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/source/_posts/2009-03-12-hash-#1.markdown diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index dfd1fc31..aa2c91b0 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -127,7 +127,7 @@ module Jekyll "year" => date.strftime("%Y"), "month" => date.strftime("%m"), "day" => date.strftime("%d"), - "title" => slug, + "title" => CGI.escape(slug), "categories" => categories.sort.join('/') }.inject(template) { |result, token| result.gsub(/:#{token.first}/, token.last) @@ -188,7 +188,8 @@ module Jekyll def write(dest) FileUtils.mkdir_p(File.join(dest, dir)) - path = File.join(dest, self.url) + # The url needs to be unescaped in order to preserve the correct filename + path = File.join(dest, CGI.unescape(self.url)) if template[/\.html$/].nil? FileUtils.mkdir_p(path) diff --git a/test/source/_posts/2009-03-12-hash-#1.markdown b/test/source/_posts/2009-03-12-hash-#1.markdown new file mode 100644 index 00000000..c6e88511 --- /dev/null +++ b/test/source/_posts/2009-03-12-hash-#1.markdown @@ -0,0 +1,6 @@ +--- +layout: default +title: Hash #1 +--- + +Hashes are nice diff --git a/test/test_post.rb b/test/test_post.rb index e01243d4..662ae76b 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -52,6 +52,13 @@ class TestPost < Test::Unit::TestCase assert_equal "/2008/10/19/foo-bar.html", @post.url end + should "CGI escape urls" do + @post.categories = [] + @post.process("2009-03-12-hash-#1.markdown") + assert_equal "/2009/03/12/hash-%231.html", @post.url + assert_equal "/2009/03/12/hash-#1", @post.id + end + should "respect permalink in yaml front matter" do file = "2008-12-03-permalinked-post.textile" @post.process(file)