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.
This commit is contained in:
parent
b7bdcb19ca
commit
a5545d5bad
|
@ -7,6 +7,7 @@ module Jekyll
|
||||||
|
|
||||||
def initialize(name)
|
def initialize(name)
|
||||||
all, path, date, slug = *name.sub(/^\//, "").match(MATCHER)
|
all, path, date, slug = *name.sub(/^\//, "").match(MATCHER)
|
||||||
|
raise ArgumentError unless all
|
||||||
@slug = path ? path + slug : slug
|
@slug = path ? path + slug : slug
|
||||||
@date = Time.parse(date)
|
@date = Time.parse(date)
|
||||||
end
|
end
|
||||||
|
@ -38,7 +39,15 @@ module Jekyll
|
||||||
def initialize(tag_name, post, tokens)
|
def initialize(tag_name, post, tokens)
|
||||||
super
|
super
|
||||||
@orig_post = post.strip
|
@orig_post = post.strip
|
||||||
|
begin
|
||||||
@post = PostComparer.new(@orig_post)
|
@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
|
end
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
|
|
|
@ -237,6 +237,22 @@ CONTENT
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "simple page with invalid post name linking" do
|
||||||
|
should "cause an error" do
|
||||||
|
content = <<CONTENT
|
||||||
|
---
|
||||||
|
title: Invalid post name linking
|
||||||
|
---
|
||||||
|
|
||||||
|
{% post_url abc2008-11-21-complex %}
|
||||||
|
CONTENT
|
||||||
|
|
||||||
|
assert_raise ArgumentError do
|
||||||
|
create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "gist tag" do
|
context "gist tag" do
|
||||||
context "simple" do
|
context "simple" do
|
||||||
setup do
|
setup do
|
||||||
|
|
Loading…
Reference in New Issue