How to split variable in zest loop

8 views
Skip to first unread message

namespace pollution

unread,
Apr 6, 2026, 1:44:14 PMApr 6
to ZAP User Group
I am using a loop to read a file in zest for some fuzzing. Each line in my file is a : delimited string like "u:p". I can't find a way to assign u to one variable and p to another within my loop. All I can do is pull out the whole line. Is there a way to do this that I have just missed and if not would it be the sort of thing I could request as an enhancement on the github?  

Simon Bennetts

unread,
Apr 15, 2026, 12:16:05 PM (6 days ago) Apr 15
to ZAP User Group
I've just worked out a solution to this.
Its not really pretty, but it works :)

I used the following statements:
  • Loop File, with the variable name "line"
    • Assign variable to string, "key" = "{{line}}"
    • Assign replace in variable, "key" replace ":.*" with "" regex=true
    • Assign variable to string, "value" = "{{line}}"
    • Assign replace in variable, "value" replace ".*:" with "" regex=true
Does that make sense?

Cheers,

Simon

JSON example below:

{
"about": "This is a Zest script. For more details about Zest visit https://github.com/zaproxy/zest/",
"zestVersion": "0.3",
"title": "ZestSplit",
"description": "A template standalone script",
"prefix": "",
"type": "StandAlone",
"parameters": {
"tokenStart": "{{",
"tokenEnd": "}}",
"tokens": {},
"elementType": "ZestVariables"
},
"statements": [
{
"set": {
"pathToFile": "/path/to/your/file.txt",
"elementType": "ZestLoopTokenFileSet"
},
"statements": [
{
"message": "Line: {{line}}",
"index": 1,
"enabled": true,
"elementType": "ZestActionPrint"
},
{
"string": "{{line}}",
"variableName": "testkey",
"index": 2,
"enabled": true,
"elementType": "ZestAssignString"
},
{
"replace": ":.*",
"replacement": "",
"regex": true,
"caseExact": false,
"variableName": "testkey",
"index": 3,
"enabled": true,
"elementType": "ZestAssignReplace"
},
{
"string": "{{line}}",
"variableName": "testvalue",
"index": 4,
"enabled": true,
"elementType": "ZestAssignString"
},
{
"replace": ".*:",
"replacement": "",
"regex": true,
"caseExact": false,
"variableName": "testvalue",
"index": 6,
"enabled": true,
"elementType": "ZestAssignReplace"
},
{
"message": "testkey \u003D {{testkey}}\ntestvalue \u003D {{testvalue}}",
"index": 7,
"enabled": true,
"elementType": "ZestActionPrint"
}
],
"variableName": "line",
"index": 2,
"enabled": true,
"elementType": "ZestLoopFile"
}
],
"authentication": [],
"options": {},
"index": 0,
"enabled": true,
"elementType": "ZestScript"
}
Reply all
Reply to author
Forward
0 new messages