-
Notifications
You must be signed in to change notification settings - Fork 170
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: Available context move to readwrite linked list. #1107
Conversation
{ | ||
"op": "set", | ||
"header": "New-Header-1", | ||
"value": "{% capture foo%}bar{% endcapture%}{{foo}}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we limit the number of allocations using the liquid lib? Otherwise, this might not be safe.
Ref:
-- Set resource limits to avoid loops |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not look like that there is a way to limit it:
https://github.com/chenxianyu2015/liquid-lua/blob/58e0a197445300538adab021d574f9375ebb6eba/lib/liquid.lua#L2610-L2620
And this one:
@@ -17,7 +17,8 @@ local function context_values() | |||
end | |||
|
|||
function _M.available_context(policies_context) | |||
return LinkedList.readonly(context_values(), policies_context) | |||
return LinkedList.readwrite({}, LinkedList.readonly( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make it read-write in the LiquidTemplateString:render
function instead?
That way other callers of this function will get a read-only list which I think is less surprising.
This commit allows users to use capture in their liquid expressions and assign variables if they needed. Due to the available_context return a readonly list, capture function cannot assign the variable and things start to mess up[0]. Due to allow users to define variables in liquid is quite bad, a new read-write linked list is created with an empty table to allow write to a temporal table. [0] Exception: ``` 2019/08/09 13:51:23 [error] 15620#15620: *9 lua entry thread aborted: runtime error: /home/centos/gateway/src/apicast/linked_list.lua:19: readonly list stack traceback: coroutine 0: [C]: in function 'error' /home/centos/gateway/src/apicast/linked_list.lua:19: in function '__newindex' ./lua_modules/share/lua/5.1/liquid.lua:2512: in function 'define_var' ./lua_modules/share/lua/5.1/liquid.lua:2459: in function 'visit' ./lua_modules/share/lua/5.1/liquid.lua:1975: in function 'render' /home/centos/gateway/src/apicast/policy/headers/headers.lua:91: in function 'run_commands' /home/centos/gateway/src/apicast/policy/headers/headers.lua:151: in function </home/centos/gateway/src/apicast/policy/headers/headers.lua:147> /home/centos/gateway/src/apicast/policy_chain.lua:200: in function 'rewrite' ...s/gateway/src/apicast/policy/local_chain/local_chain.lua:59: in function <...s/gateway/src/apicast/policy/local_chain/local_chain.lua:54> /home/centos/gateway/src/apicast/policy_chain.lua:200: in function 'rewrite' rewrite_by_lua(lua_Iy6Gdl:498):3: in main chunk, client: 172.18.0.1, server: _, request: "GET /bridge-1/?user_key=132 HTTP/1.1", host: "one" ``` Fix THREESCALE-1911 Signed-off-by: Eloy Coto <eloy.coto@gmail.com>
ed4e1a9
to
3430ba3
Compare
This commit allows users to use capture in their liquid expressions and
assign variables if they needed.
Due to the available_context return a readonly list, capture function
cannot assign the variable and things start to mess up[0]. Due to allow
users to define variables in liquid is quite bad, a new read-write
linked list is created with an empty table to allow write to a temporal
table.
[0] Exception:
Fix THREESCALE-1911
Signed-off-by: Eloy Coto eloy.coto@gmail.com