From 5d01099e22b2c78bb210c4abe70e546159070f2e Mon Sep 17 00:00:00 2001
From: Parker Moore <237985+parkr@users.noreply.github.com>
Date: Sat, 27 Mar 2021 11:36:12 -0400
Subject: [PATCH] Update include tag to be more permissive (#8618)
Merge pull request 8618
---
lib/jekyll/tags/include.rb | 2 +-
test/source/_includes/params@2.0.html | 7 +++++
test/test_tags.rb | 43 +++++++++++++++++++++++++++
3 files changed, 51 insertions(+), 1 deletion(-)
create mode 100644 test/source/_includes/params@2.0.html
diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb
index 1c3b86fe..e6fe059a 100644
--- a/lib/jekyll/tags/include.rb
+++ b/lib/jekyll/tags/include.rb
@@ -13,7 +13,7 @@ module Jekyll
!mx.freeze
FULL_VALID_SYNTAX = %r!\A\s*(?:#{VALID_SYNTAX}(?=\s|\z)\s*)*\z!.freeze
- VALID_FILENAME_CHARS = %r!^[\w/.-]+$!.freeze
+ VALID_FILENAME_CHARS = %r!^[\w/.\-()+~\#@]+$!.freeze
INVALID_SEQUENCES = %r![./]{2,}!.freeze
def initialize(tag_name, markup, tokens)
diff --git a/test/source/_includes/params@2.0.html b/test/source/_includes/params@2.0.html
new file mode 100644
index 00000000..65a00018
--- /dev/null
+++ b/test/source/_includes/params@2.0.html
@@ -0,0 +1,7 @@
+{{include.param}}
+
+
+ {% for param in include %}
+ - {{param[0]}} = {{param[1]}}
+ {% endfor %}
+
\ No newline at end of file
diff --git a/test/test_tags.rb b/test/test_tags.rb
index ac2d7779..305baf0d 100644
--- a/test/test_tags.rb
+++ b/test/test_tags.rb
@@ -907,6 +907,49 @@ class TestTags < JekyllUnitTest
end
end
+ context "with include file with special characters without params" do
+ setup do
+ content = <<~CONTENT
+ ---
+ title: special characters
+ ---
+
+ {% include params@2.0.html %}
+ CONTENT
+ create_post(content,
+ "permalink" => "pretty",
+ "source" => source_dir,
+ "destination" => dest_dir,
+ "read_posts" => true)
+ end
+
+ should "include file with empty parameters" do
+ assert_match "", @result
+ end
+ end
+
+ context "with include file with special characters with params" do
+ setup do
+ content = <<~CONTENT
+ ---
+ title: special characters
+ ---
+
+ {% include params@2.0.html param1="foobar" param2="bazbar" %}
+ CONTENT
+ create_post(content,
+ "permalink" => "pretty",
+ "source" => source_dir,
+ "destination" => dest_dir,
+ "read_posts" => true)
+ end
+
+ should "include file with empty parameters" do
+ assert_match "param1 = foobar", @result
+ assert_match "param2 = bazbar", @result
+ end
+ end
+
context "with custom includes directory" do
setup do
content = <<~CONTENT