Repository navigation
Fix inverse extended glob followed by a nested extended glob - #245
Merged
facelessuser merged 2 commits intoOct 18, 2026
Merged
Conversation
A pattern such as `!(a)@(b|*(c))` raised `re.error: missing ), unterminated subpattern` when the EXTMATCH or EXTGLOB flag was set. An inverse group is left open in the regular expression until the text that follows it is known. Finishing the nested group zeroed the count of open inverse groups, so the final cleanup for the outer group returned early and never closed it. Stop resetting the count there.
Owner
|
@spicysharkco, I believe the more appropriate approach is to decrement index = len(current) - 1
while index >= 0:
if isinstance(current[index], InvPlaceholder):
content = current[index + 1:]
if not nested:
content.append(_EOP if not self.pathname else self.path_eop)
current[index] = (
(''.join(content).replace('(?#)', '?:') if self.capture else ''.join(content)) +
(_EXCLA_GROUP_CLOSE.format(str(current[index])))
)
self.inv_ext -= 1
index -= 1 |
When `clean_up_inverse` closes an inverse group it now lowers `inv_ext` by one. A nested cleanup then leaves the count for a still open outer group alone, and the final cleanup at the end of the pattern still runs.
Contributor
Author
|
@facelessuser, done in 88b57cf: |
Owner
|
@gir-bot lgtm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fnmatch.fnmatch('xb', '!(a)@(b|*(c))', flags=fnmatch.EXTMATCH)raisesre.error: missing ), unterminated subpattern at position 5.glob.globmatch('xb', '!(a)@(b|*(c))', flags=glob.EXTGLOB)raises the same error. The pattern is valid andxbisxfollowed byb, so both should returnTrue, as Bash does. The latest release, 11.1, has the same error. It is the nested form of #218, which was fixed in #219 for!(2)_@(foo|bar).An inverse group stays open in the regular expression until the text after it is known. When a nested extended group finishes,
clean_up_inversesetsself.inv_ext = 0while the outer inverse group is still open. The final cleanup at the end of the pattern then returns early and never closes it.This removes that reset and has
clean_up_inverselowerself.inv_extby one for each inverse group it closes.I added three rows to
TestFnMatch.casesand two toTestGlobMatch.cases. Without the fix,pytest tests/test_fnmatch.pygives 3 failed, 200 passed, 1 skipped andpytest tests/test_globmatch.pygives 2 failed, 655 passed, 63 skipped. With it, they give 203 passed, 1 skipped and 657 passed, 63 skipped. The full suite passes with the fix. There is also a changelog line under Unreleased.