diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 8497dd10..b5ff5eb4 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -374,7 +374,7 @@ module Jekyll end def has_yaml_header?(file) - "---" == File.open(file) { |fd| fd.read(3) } + !!(File.open(file).read =~ /\A---\r?\n/) end def limit_posts! diff --git a/test/source/pgp.key b/test/source/pgp.key new file mode 100644 index 00000000..f7f799d3 --- /dev/null +++ b/test/source/pgp.key @@ -0,0 +1,2 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG/MacGPG2 v2.0.17 (Darwin) diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index 5419f2b9..78a49a44 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -48,6 +48,7 @@ class TestGeneratedSite < Test::Unit::TestCase should "print a nice list of static files" do expected_output = Regexp.new <<-OUTPUT - /css/screen.css last edited at \\d+ with extname .css +- /pgp.key last edited at \\d+ with extname .key - /products.yml last edited at \\d+ with extname .yml - /symlink-test/symlinked-dir/screen.css last edited at \\d+ with extname .css OUTPUT diff --git a/test/test_site.rb b/test/test_site.rb index f166c5a5..6049c147 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -187,6 +187,16 @@ class TestSite < Test::Unit::TestCase assert_equal posts.size - @num_invalid_posts, @site.posts.size end + should "read pages with yaml front matter" do + abs_path = File.expand_path("about.html", @site.source) + assert_equal true, @site.send(:has_yaml_header?, abs_path) + end + + should "enforce a strict 3-dash limit on the start of the YAML front-matter" do + abs_path = File.expand_path("pgp.key", @site.source) + assert_equal false, @site.send(:has_yaml_header?, abs_path) + end + should "expose jekyll version to site payload" do assert_equal Jekyll::VERSION, @site.site_payload['jekyll']['version'] end