dyne / restroom-mw

🛠 Easy REST API builder executing Zencode
https://restroom.dyne.org
GNU Affero General Public License v3.0
3 stars 11 forks source link

REDIS statement breaks after a few repeats #82

Closed andrea-dintino closed 2 years ago

andrea-dintino commented 2 years ago

The script below, after a few executions, returns the error:

1643639911743E[!] JSON as malformed beginning or end
1643639911743E[!] ERROR:
1643639911743E[!] EXEC: /zenroom_json.lua:35: JSON as malformed beginning or end

The script:

Rule caller restroom-mw
Given I have a valid redis connection on 'redis://localhost:6379'
Given I have a 'string' named 'redisResult'
Given I read from redis the data under the key 'myHashkey' and save the output into 'redisResult'

When I create the 'string dictionary'

When I create the random object of '256' bits

When I insert 'random object' in 'string dictionary'

When I create the 'string array'

When I insert 'string dictionary' in 'string array'

Then print the 'string array'
Then I write all data into redis under the key 'myHashkey'

When it breaks, the key in Redis contains the value:

{"string_array":[{"random_object":"�\t�Г��}�ڡ+<v�C�y)Z�\u0002\u0014��\u0017�"}]}

jaromil commented 2 years ago

@andrea-dintino the string type encoding should not be used on binary data. Also I am sure redis will not accept a json structure, it is k/v only and the way to save a struct in it is to encode it base64

andrea-dintino commented 2 years ago

Redis accepts a JSON without problem. The crash happens after a non-deterministic amount of executions of the same scripts... the first it runs, the 2nd maybe and so on

andrea-dintino commented 2 years ago

Fixed now