Skip to content

Commit a2706c6

Browse files
rbmarliererostedt
authored andcommitted
ktest: Treat undefined self-reference as empty
Config variables are expanded when they are assigned. A first-time append such as: VAR := ${VAR} foo leaves the literal ${VAR} in the stored value because VAR has not been defined yet. Later expansions then carry the self-reference forward instead of behaving like an empty prefix. Drop an unescaped self-reference when the variable has no current value, and trim the outer whitespace left behind. Keep escaped \${VAR} references unchanged so literal text still works. Cc: John Hawley <[email protected]> Cc: Andrea Righi <[email protected]> Cc: Marcos Paulo de Souza <[email protected]> Cc: Matthieu Baerts <[email protected]> Cc: Fernando Fernandez Mancera <[email protected]> Cc: Pedro Falcato <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Ricardo B. Marlière <[email protected]> Signed-off-by: Steven Rostedt <[email protected]>
1 parent eb30942 commit a2706c6

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

tools/testing/ktest/ktest.pl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,14 @@ sub set_variable {
910910
if (defined($command_tmp_vars{$lvalue})) {
911911
return;
912912
}
913+
914+
# If a variable is undefined, treat an unescaped self-reference as empty.
915+
if (!defined($variable{$lvalue})) {
916+
$rvalue =~ s/(?<!\\)\$\{\Q$lvalue\E\}//g;
917+
$rvalue =~ s/^\s+//;
918+
$rvalue =~ s/\s+$//;
919+
}
920+
913921
if ($rvalue =~ /^\s*$/) {
914922
delete $variable{$lvalue};
915923
} else {

0 commit comments

Comments
 (0)