Skip to content

Commit 1efd070

Browse files
committed
Improve safety and code clarity of function that checks for presence of context=xyz first parameter
1 parent 155808d commit 1efd070

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

transcrypt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,14 @@ die() {
136136
exit "$st"
137137
}
138138

139-
# return context name if $1 has format 'context=name-of-context' else "default"
139+
# return context name if $1 has format 'context=name-of-context' else empty string
140140
extract_context_name_from_name_value_arg() {
141-
local context=${1#*=}
142-
if [[ ! $context ]]; then
143-
echo ''
141+
local before_last_equals=${1%=*}
142+
local after_first_equals=${1#*=}
143+
if [[ "$before_last_equals" == "context" ]]; then
144+
echo "$after_first_equals"
144145
fi
145-
echo "$context"
146+
echo ''
146147
}
147148

148149
derive_context_config_group() {

0 commit comments

Comments
 (0)