mirror of
https://github.com/zsh-users/zsh
synced 2024-07-08 19:55:44 +00:00
52008: Pattern bug with branches + exclusion
Add tests.
This commit is contained in:
parent
95269147fc
commit
aa8e4a0290
|
@ -1,3 +1,8 @@
|
||||||
|
2023-08-01 Peter Stephenson <p.stephenson@samsung.com>
|
||||||
|
|
||||||
|
* 52008: Src/pattern.c, Test/D02glob.ztst: Fix bug with branches
|
||||||
|
in patterns followed by an exculsion, and add tests.
|
||||||
|
|
||||||
2023-07-31 dana <dana@dana.is>
|
2023-07-31 dana <dana@dana.is>
|
||||||
|
|
||||||
* github #100: HexorCatZ: Completion/Unix/Command/_qemu:
|
* github #100: HexorCatZ: Completion/Unix/Command/_qemu:
|
||||||
|
|
|
@ -2987,14 +2987,15 @@ patmatch(Upat prog)
|
||||||
case P_EXCSYNC:
|
case P_EXCSYNC:
|
||||||
/* See the P_EXCLUDE code below for where syncptr comes from */
|
/* See the P_EXCLUDE code below for where syncptr comes from */
|
||||||
{
|
{
|
||||||
unsigned char *syncptr;
|
unsigned char *syncstart, *syncptr, *ptr;
|
||||||
Upat after;
|
Upat after;
|
||||||
after = P_OPERAND(scan);
|
after = P_OPERAND(scan);
|
||||||
DPUTS(!P_ISEXCLUDE(after),
|
DPUTS(!P_ISEXCLUDE(after),
|
||||||
"BUG: EXCSYNC not followed by EXCLUDE.");
|
"BUG: EXCSYNC not followed by EXCLUDE.");
|
||||||
DPUTS(!P_OPERAND(after)->p,
|
DPUTS(!P_OPERAND(after)->p,
|
||||||
"BUG: EXCSYNC not handled by EXCLUDE");
|
"BUG: EXCSYNC not handled by EXCLUDE");
|
||||||
syncptr = P_OPERAND(after)->p + (patinput - patinstart);
|
syncstart = P_OPERAND(after)->p;
|
||||||
|
syncptr = syncstart + (patinput - patinstart);
|
||||||
/*
|
/*
|
||||||
* If we already matched from here, this time we fail.
|
* If we already matched from here, this time we fail.
|
||||||
* See WBRANCH code for story about error count.
|
* See WBRANCH code for story about error count.
|
||||||
|
@ -3009,6 +3010,23 @@ patmatch(Upat prog)
|
||||||
* failed anyway.
|
* failed anyway.
|
||||||
*/
|
*/
|
||||||
*syncptr = errsfound + 1;
|
*syncptr = errsfound + 1;
|
||||||
|
/*
|
||||||
|
* Because of backtracking, any match before this point
|
||||||
|
* can't apply to the current branch we're on so is now
|
||||||
|
* a failure --- this can happen if, on a previous
|
||||||
|
* branch, we initially marked a success before failing
|
||||||
|
* on a later part of the pattern after marking up the
|
||||||
|
* P_EXCSYNC (even an end anchor will have this effect).
|
||||||
|
* To make sure we record the current match point
|
||||||
|
* correctly, mark those down now.
|
||||||
|
*
|
||||||
|
* This might have side effects on the efficiency of
|
||||||
|
* pathological cases involving nested branches. To
|
||||||
|
* fix that we'd probably need to record matches on
|
||||||
|
* different branches separately.
|
||||||
|
*/
|
||||||
|
for (ptr = syncstart; ptr < syncptr; ++ptr)
|
||||||
|
*ptr = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case P_EXCEND:
|
case P_EXCEND:
|
||||||
|
|
|
@ -817,6 +817,32 @@
|
||||||
*>*/glob.tmp/(flip|flop)
|
*>*/glob.tmp/(flip|flop)
|
||||||
*>*/glob.tmp/(flip|flop)/trailing/components
|
*>*/glob.tmp/(flip|flop)/trailing/components
|
||||||
|
|
||||||
|
# The following set test an obscure problem with branches followed by
|
||||||
|
# exclusions that shows up when the exclusion matches against
|
||||||
|
# something other than the complete test string, hence the complicated
|
||||||
|
# double negative.
|
||||||
|
[[ ab = (|a*)~^(*b) ]]
|
||||||
|
0:Regression test for exclusion after branches: empty first alternative
|
||||||
|
|
||||||
|
[[ ab = (b|a*)~^(*b) ]]
|
||||||
|
0:Regression test for exclusion after branches: non-empty first alternative
|
||||||
|
|
||||||
|
[[ ab = (b*|a*)~^(*b) ]]
|
||||||
|
0:Regression test for exclusion after branches: full length first alternative
|
||||||
|
|
||||||
|
# Corresponding tests where the exclusion should succeed, so the
|
||||||
|
# match fails. It's hard to know how to provoke bugs here...
|
||||||
|
[[ abc = (|a*)~^(*b) ]]
|
||||||
|
1:Regression test for exclusion after branches: failure case 1
|
||||||
|
|
||||||
|
[[ abc = (b|a*)~^(*b) ]]
|
||||||
|
1:Regression test for exclusion after branches: failure case 2
|
||||||
|
|
||||||
|
[[ abc = (b*|a*)~^(*b) ]]
|
||||||
|
1:Regression test for exclusion after branches: failure case 3
|
||||||
|
|
||||||
|
# Careful: extendedglob off from this point.
|
||||||
|
|
||||||
unsetopt extendedglob
|
unsetopt extendedglob
|
||||||
print -r -- ${(*)=${(@s.+.):-A+B}/(#b)(?)/-${(L)match[1]} ${match[1]}}
|
print -r -- ${(*)=${(@s.+.):-A+B}/(#b)(?)/-${(L)match[1]} ${match[1]}}
|
||||||
0:the '*' qualfier enables extended_glob for pattern matching
|
0:the '*' qualfier enables extended_glob for pattern matching
|
||||||
|
|
Loading…
Reference in New Issue
Block a user