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

Liquid::Template options are not propagated on new isolated subcontext #1853

Open
narnd opened this issue Nov 15, 2024 · 0 comments
Open

Liquid::Template options are not propagated on new isolated subcontext #1853

narnd opened this issue Nov 15, 2024 · 0 comments

Comments

@narnd
Copy link

narnd commented Nov 15, 2024

Liquid::Context#new_isolated_subcontext should also set the render options strict_variables and strict_filters for the subcontext.

Maybe im missing something but I cant figure out how to raise undefined variable or undefined filter in partials using the render tag.

Please advise, happy to write a pr.

Example:

class PatchedContext < Liquid::Context
  def new_isolated_subcontext
    super.tap do |subcontext|
      subcontext.strict_variables = strict_variables
      subcontext.strict_filters = strict_filters
    end
  end
end

class FileSystem
  def read_template_file(_template_path)
    "{{ undefined_var }}{{ 'test' | undefined_filter }}"
  end
end

# normal example, no errors
liquid_context = Liquid::Context.build(registers: {file_system: FileSystem.new})
template = Liquid::Template.parse("{% render 'partial' %}")
template.render(liquid_context, strict_variables: true, strict_filters: true)
template.errors
# => []

# expected behavior, errors in partial
patched_context = PatchedContext.build(registers: {file_system: FileSystem.new})
template = Liquid::Template.parse("{% render 'partial' %}")
template.render(patched_context, strict_variables: true, strict_filters: true)
template.errors
# =>
# [#<Liquid::UndefinedVariable: Liquid error: undefined variable undefined_var>,
#  #<Liquid::UndefinedFilter: Liquid error: undefined filter undefined_filter>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant