Skip to content

Commit

Permalink
Backport update-include-tag-to-be-more-permissive from #8618 to 3.9-s…
Browse files Browse the repository at this point in the history
…table
  • Loading branch information
parkr committed Apr 6, 2021
1 parent 8fe3a5d commit 672da32
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
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

0 comments on commit 672da32

Please sign in to comment.