From a5545d5badfa204acdb8a76a409bd352ca42092f Mon Sep 17 00:00:00 2001 From: akira yamada Date: Sat, 14 Dec 2013 22:30:22 +0900 Subject: [PATCH 1/3] post_url tag raises ArgumentError for invalid name Using post_url tag with invalid name raises TypeError. It should raise ArgumentError and should display detail of the error to fix the error. --- lib/jekyll/tags/post_url.rb | 11 ++++++++++- test/test_tags.rb | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/tags/post_url.rb b/lib/jekyll/tags/post_url.rb index 063e22a4..3076b75e 100644 --- a/lib/jekyll/tags/post_url.rb +++ b/lib/jekyll/tags/post_url.rb @@ -7,6 +7,7 @@ module Jekyll def initialize(name) all, path, date, slug = *name.sub(/^\//, "").match(MATCHER) + raise ArgumentError unless all @slug = path ? path + slug : slug @date = Time.parse(date) end @@ -38,7 +39,15 @@ module Jekyll def initialize(tag_name, post, tokens) super @orig_post = post.strip - @post = PostComparer.new(@orig_post) + begin + @post = PostComparer.new(@orig_post) + rescue + raise ArgumentError.new <<-eos +Could not parse name of post "#{@orig_post}" in tag 'post_url'. + +Make sure the post exists and the name is correct. +eos + end end def render(context) diff --git a/test/test_tags.rb b/test/test_tags.rb index b21f4931..193ac998 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -237,6 +237,22 @@ CONTENT end end + context "simple page with invalid post name linking" do + should "cause an error" do + content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) + end + end + end + context "gist tag" do context "simple" do setup do From 9d259fe31562c5fb22a5ae1bbe3a60ad1cbc0743 Mon Sep 17 00:00:00 2001 From: akira yamada Date: Sun, 15 Dec 2013 17:18:11 +0900 Subject: [PATCH 2/3] added error description for invalid post name --- lib/jekyll/tags/post_url.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/tags/post_url.rb b/lib/jekyll/tags/post_url.rb index 3076b75e..52c5c2ed 100644 --- a/lib/jekyll/tags/post_url.rb +++ b/lib/jekyll/tags/post_url.rb @@ -7,7 +7,7 @@ module Jekyll def initialize(name) all, path, date, slug = *name.sub(/^\//, "").match(MATCHER) - raise ArgumentError unless all + raise ArgumentError.new("invalid post name") unless all @slug = path ? path + slug : slug @date = Time.parse(date) end From ecab2eb473bc5504b417557c88deb2fe91c6cffe Mon Sep 17 00:00:00 2001 From: akira yamada Date: Tue, 17 Dec 2013 10:57:12 +0900 Subject: [PATCH 3/3] made error description more helpful --- lib/jekyll/tags/post_url.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/tags/post_url.rb b/lib/jekyll/tags/post_url.rb index 52c5c2ed..af366702 100644 --- a/lib/jekyll/tags/post_url.rb +++ b/lib/jekyll/tags/post_url.rb @@ -7,7 +7,7 @@ module Jekyll def initialize(name) all, path, date, slug = *name.sub(/^\//, "").match(MATCHER) - raise ArgumentError.new("invalid post name") unless all + raise ArgumentError.new("'#{name}' does not contain valid date and/or title") unless all @slug = path ? path + slug : slug @date = Time.parse(date) end