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 empty regex and empty alternation parse #3507

Open
wants to merge 8 commits into
base: 1.12.x
Choose a base branch
from

Conversation

mvorisek
Copy link
Contributor

@mvorisek mvorisek commented Sep 27, 2024

@mvorisek mvorisek force-pushed the fix_empty_alternation branch 2 times, most recently from b473d7f to bcd469c Compare September 27, 2024 13:36
@mvorisek mvorisek marked this pull request as ready for review September 27, 2024 22:38
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@mvorisek mvorisek force-pushed the fix_empty_alternation branch 2 times, most recently from 9f87f5a to 4c61b1f Compare September 27, 2024 23:20
@staabm
Copy link
Contributor

staabm commented Sep 29, 2024

Do empty alternations or empty capturing groups have real world relevance?

I don't think I have ever seen a regex using it..?

@mvorisek
Copy link
Contributor Author

mvorisek commented Sep 29, 2024

They definitely do, ~@(|phpstan-)param~ is a small example.

@@ -104,13 +104,15 @@ public function dataValidate(): array
'~Result of || is always true.~',
[],
false,
true,
false,
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ondrejmirtes can you please check and let me know if there is anything to address?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ondrejmirtes would you mind sharing your review?

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

@mvorisek mvorisek force-pushed the fix_empty_alternation branch 2 times, most recently from 84a8ecf to fa1f464 Compare October 9, 2024 05:03
@mvorisek mvorisek requested a review from staabm October 10, 2024 17:02
@mvorisek mvorisek force-pushed the fix_empty_alternation branch 3 times, most recently from 3c9c813 to 94ebfb5 Compare October 13, 2024 11:52
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.

4 participants