Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## New NonRecurringFileSystem
- # Prevents horrible bug with include tag that can take out your server.
- #
- module Liquid
- class NonRecurringFileSystem
- attr_accessor :include_stack
- def initialize()
- # Stores a stack of included templates
- # so that we don't double-include and cause an infinite loop.
- @include_stack = []
- end
- def read_template_file(template_name)
- @include_stack << template_name
- # ... Do stuff to get file here and return content
- return content
- end
- end
- end
- ## Patch for include.rb that doesn't allow infinite loops
- Index: vendor/plugins/liquid/lib/liquid/tags/include.rb
- ===================================================================
- --- vendor/plugins/liquid/lib/liquid/tags/include.rb (revision 697)
- +++ vendor/plugins/liquid/lib/liquid/tags/include.rb (working copy)
- @@ -24,7 +24,10 @@
- end
- def render(context)
- - source = Liquid::Template.file_system.read_template_file(context[@template_name])
- + # Make sure not to get into infinite loops of inclusion.
- + return if Liquid::Template.file_system.include_stack.include?(context[@template_name])
- +
- + source = Liquid::Template.file_system.read_template_file(context[@template_name])
- partial = Liquid::Template.parse(source)
- variable = context[@variable_name || @template_name[1..-2]]
- @@ -48,6 +51,9 @@
- end
- end
- +
- + ensure
- + Liquid::Template.file_system.include_stack.pop
- end
- end
Add Comment
Please, Sign In to add comment