Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not using PREG_UNMATCHED_AS_NULL flag? #60

Closed
Nathanael-Shermett opened this issue Oct 3, 2021 · 0 comments · Fixed by #61
Closed

Not using PREG_UNMATCHED_AS_NULL flag? #60

Nathanael-Shermett opened this issue Oct 3, 2021 · 0 comments · Fixed by #61
Assignees

Comments

@Nathanael-Shermett
Copy link
Contributor

Nathanael-Shermett commented Oct 3, 2021

I noticed spatie/regex does not use the PREG_UNMATCHED_AS_NULL flag when it calls preg_match() and preg_match_all(). This results in inconsistent results with unmatched capturing groups.

Demo here.

I have created a pull request which fixes the issue and adds some tests. However, I wanted to verify two things:

  1. Is there a reason the flag is not being used?
  2. I noticed that MatchResult::group() uses isset() to determine whether or not a group exists. If we implement PREG_UNMATCHED_AS_NULL, that will return false for unmatched groups... which makes sense, but is also inconsistent. What is the desired behavior here?
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 a pull request may close this issue.

2 participants