Skip to content

Fix unix-ffi/re: Fix OverflowError in re.groups().#1089

Open
Josverl wants to merge 2 commits intomicropython:masterfrom
Josverl:fix_unixffe_re
Open

Fix unix-ffi/re: Fix OverflowError in re.groups().#1089
Josverl wants to merge 2 commits intomicropython:masterfrom
Josverl:fix_unixffe_re

Conversation

@Josverl
Copy link
Contributor

@Josverl Josverl commented Mar 1, 2026

Adjust the re.groups() methods to properly handle the PCRE2_UNSET value for unmatched optional groups.
This change prevents OverflowError when calling groups() on a match with no content.

The return matches CPython's.

A test case for an empty string match has been added to verify expected behavior.

Fixes micropython/micropython#18877

Fixes: micropython/micropython#18877
Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
@dpgeorge
Copy link
Member

dpgeorge commented Mar 2, 2026

Thanks for this, the fix looks good!

Can I suggest adding more tests, ie:

m = re.match(r"(.)?", "")
assert m.group() == ""
assert m.group(0, 1) == ("", None)
assert m.groups() == (None,)
assert m.groups("default") == ("default",)

That will test group() behaviour and default value.

@Josverl
Copy link
Contributor Author

Josverl commented Mar 2, 2026

Sure, happy to add.

I noticed that the readme mentions 'unsupported' for the unix-ffi folder, and I do not think these modules are included in CI testing either.

So AFIKT the tests need to be run manually, so still useful for validating.

@dpgeorge
Copy link
Member

dpgeorge commented Mar 2, 2026

I do not think these modules are included in CI testing either.

I think it is run under CI, see tools/ci.sh:ci_package_tests_run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

re groups() raises OverflowError for unmatched optional groups

2 participants