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

Prevent an internal error in include tag from non-string template_name #1648

Merged
merged 2 commits into from
Oct 28, 2022
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
2 changes: 1 addition & 1 deletion lib/liquid/tags/include.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def parse(_tokens)

def render_to_output_buffer(context, output)
template_name = context.evaluate(@template_name_expr)
raise ArgumentError, options[:locale].t("errors.argument.include") unless template_name
raise ArgumentError, options[:locale].t("errors.argument.include") unless template_name.is_a?(String)

partial = PartialCache.load(
template_name,
Expand Down
5 changes: 5 additions & 0 deletions test/integration/tags/include_tag_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ def test_render_raise_argument_error_when_template_is_undefined
"{% include nil %}", render_errors: true)
end

def test_render_raise_argument_error_when_template_is_not_a_string
assert_template_result("Liquid error (line 1): Argument error in tag 'include' - Illegal template name",
"{% include 123 %}", render_errors: true)
end

def test_including_via_variable_value
assert_template_result("from TestFileSystem", "{% assign page = 'pick_a_source' %}{% include page %}",
partials: { "pick_a_source" => "from TestFileSystem" })
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def assert_template_result(
message: nil, partials: nil, error_mode: nil, render_errors: false
)
template = Liquid::Template.parse(template, line_numbers: true, error_mode: error_mode&.to_sym)
file_system = StubFileSystem.new(partials) if partials
file_system = StubFileSystem.new(partials || {})
registers = Liquid::Registers.new(file_system: file_system)
context = Liquid::Context.build(environments: assigns, rethrow_errors: !render_errors, registers: registers)
output = template.render(context)
Expand Down