Issue 7: CGI escape post titles

Signed-off-by: Nick Quaranto <nick@quaran.to>
This commit is contained in:
Bjørn Arild Mæland 2009-04-27 13:42:24 +02:00 committed by Nick Quaranto
parent a5d236eb53
commit 4bcece18ae
3 changed files with 16 additions and 2 deletions

View File

@ -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)

View File

@ -0,0 +1,6 @@
---
layout: default
title: Hash #1
---
Hashes are nice

View File

@ -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)