[ZBX-24203] Script item error on parsing parameters if no parameters defined Created: 2024 Mar 08  Updated: 2024 Mar 12

Status: Open
Project: ZABBIX BUGS AND ISSUES
Component/s: Server (S)
Affects Version/s: 6.0.28rc1, 7.0.0beta2
Fix Version/s: None

Type: Incident report Priority: Trivial
Reporter: Gregory Chalenko Assignee: Zabbix Development Team
Resolution: Unresolved Votes: 0
Labels: parameters, scriptitem, testitem
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Steps to reproduce:

  1. Create Script item without parameters.
  2. Click "Test".

Script item body:

var input = JSON.parse(value);

return JSON.stringify(input);

Result:

Cannot execute script: SyntaxError: invalid json (at offset 1)
at [anon] (duktape.c:37568) internal
at parse () native strict preventsyield
at [anon] (function:1) preventsyield

Expected:
No errors. Empty string is returned.



 Comments   
Comment by Gregory Chalenko [ 2024 Mar 08 ]

No error when script check is value set or not.

var input = value ? JSON.parse(value) : {};

return JSON.stringify(input); 
Comment by dimir [ 2024 Mar 11 ]

It was suggested to introduce a new predefined variable e. g. "params" that would be an object representing script parameters. This way we will not break existing code that somehow relies on variable named "value" that is expected to be an empty string.

I guess we should be careful in this case and think of the case when "params" variable is already taken in the old code.

Comment by Vjaceslavs Bogdanovs [ 2024 Mar 12 ]

There is no problem if the param is used in existing code as it would be redefined without problems.

Comment by dimir [ 2024 Mar 12 ]

Indeed, JS can do wonders:

var params = 5;
console.log("params=" + params);

var params = 'foo';
console.log("params=" + params);

Output:

params=5
params=foo

No warnings issued.

Generated at Tue Jun 24 06:39:54 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.