Skip to content

Commit 4af7d09

Browse files
committed
perf(runner): collapse metachar check to single regex in parse_data_provider_args
Merge the leading-metachar and embedded-metachar grep calls at src/runner.sh:263 into one `(^|[^\])[|&;*]` pattern. Saves one grep subprocess per parametrized test invocation. Bash 3.0+ compatible.
1 parent 2582b33 commit 4af7d09

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/runner.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,11 @@ function bashunit::runner::parse_data_provider_args() {
269269
local -a args=()
270270
local args_count=0
271271

272-
# Check for shell metacharacters that would break eval or cause globbing
272+
# Check for unescaped shell metacharacters that would break eval or cause
273+
# globbing. Combines the leading-metachar case and the embedded-metachar
274+
# case into a single regex to avoid a second grep subprocess per call.
273275
local has_metachar=false
274-
local _re1='[^\\][\|\&\;\*]'
275-
local _re2='^[\|\&\;\*]'
276-
if [ "$(echo "$input" | "$GREP" -cE "$_re1" || true)" -gt 0 ] \
277-
|| [ "$(echo "$input" | "$GREP" -cE "$_re2" || true)" -gt 0 ]; then
276+
if [ "$(echo "$input" | "$GREP" -cE '(^|[^\])[|&;*]' || true)" -gt 0 ]; then
278277
has_metachar=true
279278
fi
280279

0 commit comments

Comments
 (0)