From e39810c98411bd2c459f4e816449af554991e4e6 Mon Sep 17 00:00:00 2001 From: Stefan Saasen Date: Sun, 24 May 2009 12:26:12 +1200 Subject: [PATCH] Fix exception that causes jekyll to fail when using CRLF (0d0a) linebreaks in YAML front matter. Signed-off-by: Nick Quaranto --- lib/jekyll/convertible.rb | 4 ++-- .../win/_posts/2009-05-24-yaml-linebreak.markdown | 7 +++++++ test/test_post.rb | 13 +++++++++++++ test/test_site.rb | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 test/source/win/_posts/2009-05-24-yaml-linebreak.markdown diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index 4d2ec17f..fd457177 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -18,10 +18,10 @@ module Jekyll def read_yaml(base, name) self.content = File.read(File.join(base, name)) - if self.content =~ /^(---\s*\n.*?)\n---\s*\n/m + if self.content =~ /^(---\s*\n.*?)\r?\n---\s*\n/m self.content = self.content[($1.size + 5)..-1] - self.data = YAML.load($1) + self.data = YAML.load($1.dup) end end diff --git a/test/source/win/_posts/2009-05-24-yaml-linebreak.markdown b/test/source/win/_posts/2009-05-24-yaml-linebreak.markdown new file mode 100644 index 00000000..0797531c --- /dev/null +++ b/test/source/win/_posts/2009-05-24-yaml-linebreak.markdown @@ -0,0 +1,7 @@ +--- +layout: post +title: "Test title" +tag: "Ruby" +--- + +This is the content \ No newline at end of file diff --git a/test/test_post.rb b/test/test_post.rb index f6816be0..ed8a4d2d 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -68,6 +68,19 @@ class TestPost < Test::Unit::TestCase assert_equal "my_category/permalinked-post", @post.url end + context "with CRLF linebreaks" do + setup do + @real_file = "2009-05-24-yaml-linebreak.markdown" + @source = source_dir('win/_posts') + end + should "read yaml front-matter" do + @post.read_yaml(@source, @real_file) + + assert_equal({"title" => "Test title", "layout" => "post", "tag" => "Ruby"}, @post.data) + assert_equal "\r\n\r\nThis is the content", @post.content + end + end + context "with site wide permalink" do setup do @post.categories = [] diff --git a/test/test_site.rb b/test/test_site.rb index 469c2a8b..f2202c8b 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -42,7 +42,7 @@ class TestSite < Test::Unit::TestCase @site.process posts = Dir[source_dir("**", "_posts", "*")] - categories = %w(bar baz category foo z_category publish_test).sort + categories = %w(bar baz category foo z_category publish_test win).sort assert_equal posts.size - 1, @site.posts.size assert_equal categories, @site.categories.keys.sort