From eee3a672b6f6b371ac34d2151bb44a14bea90833 Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Fri, 5 Oct 2018 10:16:26 +0200 Subject: [PATCH] fix passing filesystem when rendering partials --- lib/liquid.lua | 2 +- t/interpreter.t | 29 +++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/liquid.lua b/lib/liquid.lua index 69b3852..cb13510 100644 --- a/lib/liquid.lua +++ b/lib/liquid.lua @@ -2407,7 +2407,7 @@ function Interpreter:visit_Partial( node ) end end local interpreter = Interpreter:new(parser) - local result = interpreter:interpret(context, self.filterset, self.resourcelimit) + local result = interpreter:interpret(context, self.filterset, self.resourcelimit, self.filesystem) context:destroyframe() self.resourcelimit:check_length(#result) return result diff --git a/t/interpreter.t b/t/interpreter.t index 71341af..53be83b 100644 --- a/t/interpreter.t +++ b/t/interpreter.t @@ -341,23 +341,36 @@ GET /t local Interpreter = Liquid.Interpreter local FileSystem = Liquid.FileSystem local InterpreterContext = Liquid.InterpreterContext - local var = {["aa"] = "-----", ["bb"] = { ["cc"] = "======" } } - local document = "{% if true %} abc{{ aa }}defg {% endif %} {% include 'foo' for bb %} {% include 'foo' %} " - local function mock_template() - return [[{% if true %} 12345{{ cc }}6789 {% endif %}]] + local var = { + ["aa"] = "-----", + ["bb"] = { ["cc"] = "======" }, + } + local document = [[ + {%- if true -%} + abc{{ aa }}defg + {%- endif %} + {%- include 'foo' for bb -%} + {%- include 'foo' -%} + {%- include 'bar' -%} + ]] + local filesystem = { + foo = [[{% if true %} 12345{{ cc }}6789 {% endif %}]], + bar = [[{% include 'recursive' %}]], + recursive = [[bar]], + } + local function mock_template(name) + return filesystem[name] end - FileSystem.get = mock_template local lexer = Lexer:new(document) local parser = Parser:new(lexer) local interpreter = Interpreter:new(parser) - ngx.say( interpreter:interpret( InterpreterContext:new(var) ) ) + ngx.say( interpreter:interpret( InterpreterContext:new(var), nil, nil, FileSystem:new(mock_template) ) ) } } --- request GET /t --- response_body - abc-----defg 12345======6789 123456789 - +abc-----defg 12345======6789 123456789 bar --- no_error_log [error]