ClickAndMortar / AdvancedCsvConnectorBundle

Advanced CSV Connector Bundle for Akeneo
https://www.clickandmortar.fr/blog/akeneo-csv-advanced-connector
22 stars 5 forks source link

Error recording a lua script #28

Closed Philippe-M closed 4 years ago

Philippe-M commented 4 years ago

I'm trying to write the following lua script with Akaneo 3.2.17 CE with ACCB 1.6

num = attributeValue*12
str = tostring(num)

return str

But I have the error when I want to save the script

image

In log i've

[2019-11-13 11:08:32] request.INFO: Matched route "pim_customentity_rest_edit". {"route":"pim_customentity_rest_edit","route_parameters":{"_controller":"pim_custom_entity.controller:executeAction","actionType":"rest_update","customEntityName":"luaUpdater","id":"3","_route":"pim_customentity_rest_edit"},"request_uri":"http://svmedia01dev/reference-data/rest/luaUpdater/3/edit","method":"POST"} []
[2019-11-13 11:08:32] request.CRITICAL: Uncaught PHP Exception LuaException: "[string "line"]:3: attempt to call global 'tostring' (a nil value)" at /var/www/html/pim-community-standard/vendor/clickandmortar/advanced-csv-connector-bundle/Validator/LuaScriptValidator.php line 46 {"exception":"[object] (LuaException(code: 1): [string \"line\"]:3: attempt to call global 'tostring' (a nil value) at /var/www/html/pim-community-standard/vendor/clickandmortar/advanced-csv-connector-bundle/Validator/LuaScriptValidator.php:46)"} []

I tested on my machine with a local lua script

num = 2*12
str = tostring(num)

print(str)
#lua test.lua 
24
simoncarre commented 4 years ago

Hello @Philippe-M,

We have applied limits on LUA scripts for security reasons. Only string and math libraries could be used :

/**
     * LUA script prefix used to limit functions
     *
     * @var string
     */
    const LUA_SCRIPT_PREFIX = 'local _ENV = { attributeValue = attributeValue, string = string, math = math}';

I just updated on version 1.6 & 1.7 the list of functions that can be now used:

/**
     * LUA script prefix used to limit functions
     *
     * @var string
     */
    const LUA_SCRIPT_PREFIX = 'local _ENV = { attributeValue = attributeValue, string = string, math = math, ipairs = ipairs, load = load, next = next, pairs = pairs, rawequal = rawequal, rawget = rawget, rawlen = rawlen, rawset = rawset, select = select, tonumber = tonumber, tostring = tostring, type = type}';