Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where post_url tag matched incorrect post with subdirectory #4873

Merged
merged 3 commits into from Oct 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/jekyll/tags/post_url.rb
Expand Up @@ -14,7 +14,8 @@ def initialize(name)
"'#{name}' does not contain valid date and/or title."
end

@name_regex = %r!^#{path}#{date}-#{slug}\.[^.]+!
@name_regex = %r!^_posts/#{path}#{date}-#{slug}\.[^.]+|
^#{path}_posts/?#{date}-#{slug}\.[^.]+!x
end

def post_date
Expand All @@ -23,7 +24,7 @@ def post_date
end

def ==(other)
other.basename.match(@name_regex)
other.relative_path.match(@name_regex)
end

def deprecated_equality(other)
Expand Down
34 changes: 34 additions & 0 deletions test/test_tags.rb
Expand Up @@ -587,6 +587,40 @@ def highlight_block_with_opts(options_string)
end
end

context "simple page with nested post linking and path not used in `post_url`" do
setup do
content = <<CONTENT
---
title: Deprecated Post linking
---

- 1 {% post_url 2008-11-21-nested %}
CONTENT
create_post(content, {
"permalink" => "pretty",
"source" => source_dir,
"destination" => dest_dir,
"read_posts" => true
})
end

should "not cause an error" do
refute_match(%r!markdown\-html\-error!, @result)
end

should "have the url to the \"nested\" post from 2008-11-21" do
assert_match %r!1\s/2008/11/21/nested/!, @result
end

should "throw a deprecation warning" do
deprecation_warning = " Deprecation: A call to "\
"'{{ post_url 2008-11-21-nested }}' did not match a post using the new matching "\
"method of checking name (path-date-slug) equality. Please make sure that you "\
"change this tag to match the post's name exactly."
assert_includes Jekyll.logger.messages, deprecation_warning
end
end

context "simple page with invalid post name linking" do
should "cause an error" do
content = <<CONTENT
Expand Down