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

Backport #8618 for v3.9.x: Update include tag to be more permissive #8629

Merged
merged 1 commit into from Apr 7, 2021
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
6 changes: 3 additions & 3 deletions lib/jekyll/tags/include.rb
Expand Up @@ -21,9 +21,9 @@ class IncludeTag < Liquid::Tag
(?<params>.*)
!mx

FULL_VALID_SYNTAX = %r!\A\s*(?:#{VALID_SYNTAX}(?=\s|\z)\s*)*\z!
VALID_FILENAME_CHARS = %r!^[\w/\.-]+$!
INVALID_SEQUENCES = %r![./]{2,}!
FULL_VALID_SYNTAX = %r!\A\s*(?:#{VALID_SYNTAX}(?=\s|\z)\s*)*\z!.freeze
VALID_FILENAME_CHARS = %r!^[\w/.\-()+~\#@]+$!.freeze
INVALID_SEQUENCES = %r![./]{2,}!.freeze

def initialize(tag_name, markup, tokens)
super
Expand Down
7 changes: 7 additions & 0 deletions test/source/_includes/params@2.0.html
@@ -0,0 +1,7 @@
<span id='include-param'>{{include.param}}</span>

<ul id='param-list'>
{% for param in include %}
<li>{{param[0]}} = {{param[1]}}</li>
{% endfor %}
</ul>
43 changes: 43 additions & 0 deletions test/test_tags.rb
Expand Up @@ -1093,6 +1093,49 @@ def highlight_block_with_opts(options_string)
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 "<span id=\"include-param\"></span>", @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 "<li>param1 = foobar</li>", @result
assert_match "<li>param2 = bazbar</li>", @result
end
end

context "with custom includes directory" do
setup do
content = <<CONTENT
Expand Down