Guest User

Untitled

a guest
Apr 17th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. ## New NonRecurringFileSystem
  2.  
  3. # Prevents horrible bug with include tag that can take out your server.
  4. #
  5.  
  6. module Liquid
  7. class NonRecurringFileSystem
  8. attr_accessor :include_stack
  9. def initialize()
  10. # Stores a stack of included templates
  11. # so that we don't double-include and cause an infinite loop.
  12. @include_stack = []
  13. end
  14.  
  15. def read_template_file(template_name)
  16. @include_stack << template_name
  17. # ... Do stuff to get file here and return content
  18. return content
  19. end
  20. end
  21. end
  22.  
  23. ## Patch for include.rb that doesn't allow infinite loops
  24.  
  25. Index: vendor/plugins/liquid/lib/liquid/tags/include.rb
  26. ===================================================================
  27. --- vendor/plugins/liquid/lib/liquid/tags/include.rb (revision 697)
  28. +++ vendor/plugins/liquid/lib/liquid/tags/include.rb (working copy)
  29. @@ -24,7 +24,10 @@
  30. end
  31.  
  32. def render(context)
  33. - source = Liquid::Template.file_system.read_template_file(context[@template_name])
  34. + # Make sure not to get into infinite loops of inclusion.
  35. + return if Liquid::Template.file_system.include_stack.include?(context[@template_name])
  36. +
  37. + source = Liquid::Template.file_system.read_template_file(context[@template_name])
  38. partial = Liquid::Template.parse(source)
  39.  
  40. variable = context[@variable_name || @template_name[1..-2]]
  41. @@ -48,6 +51,9 @@
  42.  
  43. end
  44. end
  45. +
  46. + ensure
  47. + Liquid::Template.file_system.include_stack.pop
  48. end
  49. end
Add Comment
Please, Sign In to add comment