From 4c7363068651f222be6150050bb3aa9823ca6f78 Mon Sep 17 00:00:00 2001 From: Massimiliano Minella Date: Thu, 8 Feb 2024 15:58:27 +0100 Subject: cmd: setexpr: fix no matching string in gsub return empty value In gsub, when the destination string is empty, the string 't' is provided and the regular expression doesn't match, then the final result is an empty string. Example: => echo ${foo} => setenv foo => setexpr foo gsub e a bar => echo ${foo} => The variable ${foo} should contain "bar" and the lack of match shouldn't be considered an error. This patch fixes the erroneous behavior by removing the return statement and breaking out of the loop in case of lack of match. Also add a test for the no match case. Signed-off-by: Massimiliano Minella --- doc/usage/cmd/setexpr.rst | 1 + 1 file changed, 1 insertion(+) (limited to 'doc/usage/cmd/setexpr.rst') diff --git a/doc/usage/cmd/setexpr.rst b/doc/usage/cmd/setexpr.rst index d245a13ca88..593a0ea91e1 100644 --- a/doc/usage/cmd/setexpr.rst +++ b/doc/usage/cmd/setexpr.rst @@ -39,6 +39,7 @@ setexpr name gsub [] string , substitute the string . The result is assigned to . If is not supplied, use the old value of . + If no substring matching is found in , assign to . setexpr name sub [] Just like gsub(), but replace only the first matching substring -- cgit v1.2.3