From bbdeb32f38727113b274367c340599bcb9c54014 Mon Sep 17 00:00:00 2001 From: Eldritch Cheese Date: Sat, 26 Nov 2016 16:51:01 -0500 Subject: [PATCH 1/4] Escaped regular expressions when using post_url. Previously, the post_url function would give error messages when the post being listed contained special characters for use in regular expressions. These special characters are now escaped using Regexp.escape. --- lib/jekyll/tags/post_url.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/tags/post_url.rb b/lib/jekyll/tags/post_url.rb index b865cd67..9b4203d6 100644 --- a/lib/jekyll/tags/post_url.rb +++ b/lib/jekyll/tags/post_url.rb @@ -14,7 +14,8 @@ module Jekyll "'#{name}' does not contain valid date and/or title." end - @name_regex = %r!^_posts/#{path}#{date}-#{slug}\.[^.]+| + escaped_slug = Regexp.escape(slug) + @name_regex = %r!^_posts/#{path}#{date}-#{escaped_slug}\.[^.]+| ^#{path}_posts/?#{date}-#{slug}\.[^.]+!x end From a55760d4ad9fe3a00d4bfcd6e74512f4132d8cfe Mon Sep 17 00:00:00 2001 From: Eldritch Cheese Date: Sat, 26 Nov 2016 22:31:03 -0500 Subject: [PATCH 2/4] Added unit test for special character, fixed error that it exposed. --- lib/jekyll/tags/post_url.rb | 2 +- .../2016-11-26-special-chars-(+).markdown | 8 ++++++ test/test_tags.rb | 26 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/source/_posts/2016-11-26-special-chars-(+).markdown diff --git a/lib/jekyll/tags/post_url.rb b/lib/jekyll/tags/post_url.rb index 9b4203d6..37c7e565 100644 --- a/lib/jekyll/tags/post_url.rb +++ b/lib/jekyll/tags/post_url.rb @@ -16,7 +16,7 @@ module Jekyll escaped_slug = Regexp.escape(slug) @name_regex = %r!^_posts/#{path}#{date}-#{escaped_slug}\.[^.]+| - ^#{path}_posts/?#{date}-#{slug}\.[^.]+!x + ^#{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_tags.rb b/test/test_tags.rb index 6bf4b84b..0a277173 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 \"complex\" post from 2008-11-21" do + assert_match %r!/2016/11/26/special-chars-\(\+\)/!, @result + end + end + context "simple page with nested post linking" do setup do content = < Date: Sun, 27 Nov 2016 07:59:56 -0500 Subject: [PATCH 3/4] Increased number of posts in test_generated_site to account for special chars test --- test/test_generated_site.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 467bd5bb321a94a5aae0812f55f45b6ca3c273bc Mon Sep 17 00:00:00 2001 From: Eldritch Cheese Date: Mon, 28 Nov 2016 07:35:48 -0500 Subject: [PATCH 4/4] Updated test name, using single quotes for cleanliness. --- test/test_tags.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_tags.rb b/test/test_tags.rb index 0a277173..bd75cb53 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -575,7 +575,7 @@ CONTENT refute_match(%r!markdown\-html\-error!, @result) end - should "have the URL to the \"complex\" post from 2008-11-21" do + 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