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

Fix error in PregMatchTypeSpecifyingExtension #28

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jul 11, 2024

should fix a crash in when running on the composer project, as discussed in #27 (comment)

@Seldaek Seldaek merged commit 1f78dac into composer:2.x Jul 11, 2024
11 of 12 checks passed
@staabm staabm deleted the patch-1 branch July 11, 2024 14:41
@staabm
Copy link
Contributor Author

staabm commented Jul 11, 2024

btw: I just saw errors in composer repo beeing reported in

https://github.com/composer/composer/blob/07aee7ea8e1ab691c14bfe4258f826a8aae95ed3/src/Composer/Util/Git.php#L408

comparisons are a known problem: phpstan/phpstan#11293

@staabm
Copy link
Contributor Author

staabm commented Jul 11, 2024

turn
if (Preg::match('{^\s*HEAD branch:\s(.+)\s*$}m', $line, $matches) > 0) {
into
if (Preg::isMatch('{^\s*HEAD branch:\s(.+)\s*$}m', $line, $matches)) {
and it should work

@Seldaek
Copy link
Member

Seldaek commented Jul 11, 2024

Thanks, this is awesome already :)

And with phpstan 1.11.x-dev gets even better. As a frequent regex user I absolutely love this :D

Yeah a few places weren't migrated to isMatch but they really ought to IMO.

I've checked and indeed it seems like with all fixes in, isMatchStrictGroups isn't really needed anymore.. However I kinda like it as it still does runtime enforcement, but what I think would be even cooler is if we can detect with PHPStan that the regex contains optional groups.. and error because isMatchStrictGroups is not safe and might throw.

@staabm
Copy link
Contributor Author

staabm commented Jul 11, 2024

but what I think would be even cooler is if we can detect with PHPStan that the regex contains optional groups.. and error because isMatchStrictGroups is not safe and might throw.

the array-shape-matcher already detects optional groups.

if you can bring up examples of what you want todo I can look into it

@Seldaek
Copy link
Member

Seldaek commented Jul 11, 2024

Yeah I realize it does it already, that's why I think it might be fairly simple to detect when strict-group functions have a shape that has nullable groups, then it'll possibly throw, and the regex needs adjusting. I'll open a PR with tests.

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.

2 participants