diff options
author | Massimiliano Minella <massimiliano.minella@se.com> | 2024-02-08 15:58:27 +0100 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2024-03-02 12:26:19 -0500 |
commit | 4c7363068651f222be6150050bb3aa9823ca6f78 (patch) | |
tree | d105f051213ba03aaf0b50a1bced135a463a7a4a /test | |
parent | fd50ae3f2628d1197829e0c2ef52aed653e80d68 (diff) | |
download | u-boot-4c7363068651f222be6150050bb3aa9823ca6f78.zip u-boot-4c7363068651f222be6150050bb3aa9823ca6f78.tar.gz u-boot-4c7363068651f222be6150050bb3aa9823ca6f78.tar.bz2 |
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 <massimiliano.minella@se.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/cmd/setexpr.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/cmd/setexpr.c b/test/cmd/setexpr.c index 312593e..ee329e9 100644 --- a/test/cmd/setexpr.c +++ b/test/cmd/setexpr.c @@ -179,6 +179,16 @@ static int setexpr_test_regex(struct unit_test_state *uts) val = env_get("mary"); ut_asserteq_str("this is a test", val); + /* No match */ + ut_assertok(run_command("setenv fred 'this is a test'", 0)); + ut_assertok(run_command("setenv mary ''", 0)); + ut_assertok(run_command("setexpr fred gsub us is \"${fred}\"", 0)); + ut_assertok(run_command("setexpr mary gsub us is \"${fred}\"", 0)); + val = env_get("fred"); + ut_asserteq_str("this is a test", val); + val = env_get("mary"); + ut_asserteq_str("this is a test", val); + unmap_sysmem(buf); return 0; |