From 823c863a537c93e310a7a819074c7f0945050273 Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Sat, 5 Apr 2014 17:34:08 -0400 Subject: [PATCH 1/5] require newline after start of yaml header --- lib/jekyll/site.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 0e7ddac3..b67fe8cd 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) } + "---\n" == File.open(file) { |fd| fd.read(4) } end def limit_posts! From 6c0f40385c717ab42d74f69dcf7b5626e638da2e Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Sun, 6 Apr 2014 16:03:19 -0400 Subject: [PATCH 2/5] add test for PGP key yaml frontmatter --- test/source/pgp.key | 2 ++ test/test_generated_site.rb | 1 + test/test_site.rb | 10 ++++++++++ 3 files changed, 13 insertions(+) create mode 100644 test/source/pgp.key 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 86b5f0c2..1c5979c9 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..a66988c5 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 "not read PGP keys as pages" 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 From 387cf2181addb0657f513cac6e38edb1e61fd1de Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Fri, 11 Apr 2014 08:00:40 -0400 Subject: [PATCH 3/5] use regex to verify yaml existence --- lib/jekyll/site.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index b67fe8cd..f6fc89c0 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -374,7 +374,7 @@ module Jekyll end def has_yaml_header?(file) - "---\n" == File.open(file) { |fd| fd.read(4) } + !!(File.open(file).read =~ /^---\r?\n/) end def limit_posts! From b666ac787bd0771532e295bb3466b8d71beb2b6c Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Fri, 11 Apr 2014 15:15:37 -0400 Subject: [PATCH 4/5] Stricter start of line check via \A --- lib/jekyll/site.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index f6fc89c0..ecfaa6a7 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).read =~ /^---\r?\n/) + !!(File.open(file).read =~ /\A---\r?\n/) end def limit_posts! From 658f418400acecf0895b73ef5de3bdbf3a92e5f6 Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Mon, 14 Apr 2014 12:15:16 -0400 Subject: [PATCH 5/5] more explicit test description --- test/test_site.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_site.rb b/test/test_site.rb index a66988c5..6049c147 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -192,7 +192,7 @@ class TestSite < Test::Unit::TestCase assert_equal true, @site.send(:has_yaml_header?, abs_path) end - should "not read PGP keys as pages" do + 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