apache / apache/jmeter

User defined variables - support for regex group replace

Open
#6,066 0 comments 0 reactions 0 assignees View on GitHub
enhancement to-triage
Dominant language
Java
Stars
9.5k
Forks
2.3k
Avg merge
1d 22h
Merged PRs (30d)
5

Description

### Use case

UDV now only supports replacing the whole value match for `${variableName}`.
1) Sometimes the parameter values are not unique enough
E.g. in request body
`TENANT_ID|1|STYLE_ID|1`
a value match "1" is not unique enough to identify tenantId variable and 2 replacements would be done.
`TENANT_ID|${tenantId}|STYLE_ID|${tenantId}`
2) or are not needed at all to place a new variable into test.
E.g. in request body
`TENANT_ID|1|STYLE_ID|1`
match value of "1" is not needed and better way would be looking for parameter name "TENANT_ID".

### Possible solution

Support regex group matching and replacing
E.g. in request body
`TENANT_ID|1|STYLE_ID|1`
for pattern:
`(?\bTENANT_ID\|)(?[0-9]+?)(?\|\b)`
groups prefix and suffix would be copied without change, value group would be replaced by the variable ${tenantId}.
result would be
`TENANT_ID|${tenantId}|STYLE_ID|1`
Pattern is able to identify variables without even knowing the value of the parameter in request body, it matches any number.
Although a static value could be used `(?\bTENANT_ID\|)(?123)(?\|\b)` too.

Please see the attached patch
[ReplaceFunctionsWithStrings.patch](https://github.com/apache/jmeter/files/12396493/ReplaceFunctionsWithStrings.patch)
Only java regex are implemented, not oro.
Method transformValueWithJavaRegex is made protected to be used in unit tests.
UDV values that contain regex for group replace would be identified by '*' at their start for backward compatibility.

![image](https://github.com/apache/jmeter/assets/21262290/553792a3-69ea-4575-877f-6b551da6d6d9)

### Possible workarounds

_No response_

### JMeter Version

5.6.2

### Java Version

17

### OS Version

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.