diff --git a/lib/jekyll/tags/post_url.rb b/lib/jekyll/tags/post_url.rb index b865cd67..37c7e565 100644 --- a/lib/jekyll/tags/post_url.rb +++ b/lib/jekyll/tags/post_url.rb @@ -14,8 +14,9 @@ module Jekyll "'#{name}' does not contain valid date and/or title." end - @name_regex = %r!^_posts/#{path}#{date}-#{slug}\.[^.]+| - ^#{path}_posts/?#{date}-#{slug}\.[^.]+!x + escaped_slug = Regexp.escape(slug) + @name_regex = %r!^_posts/#{path}#{date}-#{escaped_slug}\.[^.]+| + ^#{path}_posts/?#{date}-#{escaped_slug}\.[^.]+!x end def post_date diff --git a/test/source/_posts/2016-11-26-special-chars-(+).markdown b/test/source/_posts/2016-11-26-special-chars-(+).markdown new file mode 100644 index 00000000..21cc7714 --- /dev/null +++ b/test/source/_posts/2016-11-26-special-chars-(+).markdown @@ -0,0 +1,8 @@ +--- +layout: default +title: Special Characters +--- + +url: {{ page.url }} +date: {{ page.date }} +id: {{ page.id }} \ No newline at end of file diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index 112cf9d3..3a520b24 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -11,7 +11,7 @@ class TestGeneratedSite < JekyllUnitTest end should "ensure post count is as expected" do - assert_equal 50, @site.posts.size + assert_equal 51, @site.posts.size end should "insert site.posts into the index" do diff --git a/test/test_tags.rb b/test/test_tags.rb index 6bf4b84b..bd75cb53 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -554,6 +554,32 @@ CONTENT end end + context "simple page with post linking containing special characters" do + setup do + content = < "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 "special-chars" post from 2016-11-26' do + assert_match %r!/2016/11/26/special-chars-\(\+\)/!, @result + end + end + context "simple page with nested post linking" do setup do content = <