Correct behavior of string match variable import with multiple arguments

This refactors the behavior of string match with capture groups to
correctly handle multiple arguments. Now the variable capture applies to
the first match, as documented. Fixes #7938.
This commit is contained in:
ridiculousfish
2021-04-20 15:15:13 -07:00
parent abd59c50b0
commit f4bcfd9085
3 changed files with 127 additions and 82 deletions

View File

@@ -97,3 +97,26 @@ set --show text
# CHECK: $text[2]: |aaa|
# CHECK: $text[3]: ||
# CHECK: $text[4]: |bbb|
# Regression test for #7938.
set -e text
echo one\ntwo | string match -ra '(?<text>[a-z]+)'
# CHECK: one
# CHECK: one
# CHECK: two
# CHECK: two
set --show text
# CHECK: $text: set in global scope, unexported, with 1 elements
# CHECK: $text[1]: |one|
set -e text
echo three\nfour | string match -qra '(?<text>[a-z]+)'
set --show text
# CHECK: $text: set in global scope, unexported, with 1 elements
# CHECK: $text[1]: |three|
set -e text
echo 555\nsix | string match -qra '(?<text>[a-z]+)'
set --show text
# CHECK: $text: set in global scope, unexported, with 1 elements
# CHECK: $text[1]: |six|