diff options
| author | Massimiliano Minella <[email protected]> | 2024-02-08 15:58:27 +0100 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2024-03-02 12:26:19 -0500 |
| commit | 4c7363068651f222be6150050bb3aa9823ca6f78 (patch) | |
| tree | d105f051213ba03aaf0b50a1bced135a463a7a4a /doc/usage/cmd/setexpr.rst | |
| parent | fd50ae3f2628d1197829e0c2ef52aed653e80d68 (diff) | |
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 <[email protected]>
Diffstat (limited to 'doc/usage/cmd/setexpr.rst')
| -rw-r--r-- | doc/usage/cmd/setexpr.rst | 1 |
1 files changed, 1 insertions, 0 deletions
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 <r> <s> [<t>] string <t>, substitute the string <s>. The result is assigned to <name>. If <t> is not supplied, use the old value of <name>. + If no substring matching <r> is found in <t>, assign <t> to <name>. setexpr name sub <r> <s> [<t>] Just like gsub(), but replace only the first matching substring |
