-
Notifications
You must be signed in to change notification settings - Fork 506
Fix empty regex and empty alternation parse #3507
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
Conversation
b473d7f
to
bcd469c
Compare
bcd469c
to
d79f280
Compare
This pull request has been marked as ready for review. |
9f87f5a
to
4c61b1f
Compare
Do empty alternations or empty capturing groups have real world relevance? I don't think I have ever seen a regex using it..? |
They definitely do, |
@@ -104,13 +104,15 @@ public function dataValidate(): array | |||
'~Result of || is always true.~', | |||
[], | |||
false, | |||
true, | |||
false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a blocker, I can't merge this. This is the main reason why IgnoredRegexValidator exists at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ondrejmirtes if I understand the test correctly it was rejecting ...||...
regex but the regex is valid, |
is an alternation regex token and thus ||
means alternation with empty string which is fixed by this PR, would you mind amending the test and pushing to by branch directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IgnoredRegexValidator makes sure that if people have this in their configuration:
parameters:
ignoreErrors:
- '~Result of || is always true.~'
It makes PHPStan fail with the following error:
Invalid entry in ignoreErrors:
Ignored error ~Result of || is always true.~ has an unescaped '||' which leads to ignoring all errors. Use '\|\|' instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but it MUST NOT fail, as it is valid regex :)
So please tell me how to make everyone happy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a valid regex for ignoreErrors
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe in December, after I release 2.0. Don't expect it sooner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bugfix into 1.12.x, might I understand why so late?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I have different priorities and this is not a severe bug affecting a lot of users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ondrejmirtes is now a better time?
About the usecase, see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.65.0/src/DocBlock/TypeExpression.php#L62 for example.
(a|b|)
is shorter syntax of ((?:a|b|)?)
, the first one is currently now parsed by PHPStan and this PR fixes it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ondrejmirtes, please review, the feedback was addressed.
4c61b1f
to
7230e5d
Compare
84a8ecf
to
fa1f464
Compare
3c9c813
to
94ebfb5
Compare
94ebfb5
to
aec975a
Compare
aec975a
to
efc81bc
Compare
efc81bc
to
f40aae6
Compare
This pull request has been marked as ready for review. |
Looks fine, thank you. |
Thank you ❤ |
fix phpstan/phpstan#11762