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

Generated baseline can't be used if regex can't be compilated to UTF-8 chars #3835

Draft
wants to merge 14 commits into
base: 1.12.x
Choose a base branch
from

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Feb 22, 2025

closes phpstan/phpstan#12629

observations:

  • baseline generation crashed PHPStan before this fix
Fatal error: Uncaught Nette\Neon\Exception: Invalid UTF-8 sequence: #^Regex pattern is invalid\: Compilation failed\: UTF\-8 error\: byte 2 top bits not 0x80 at offset 0 in pattern\: \!�\[�\-�\]\!u$# in /Users/staabm/workspace/phpstan-src/vendor/nette/neon/src/Neon/Node/StringNode.php:84
Stack trace:
#0 /Users/staabm/workspace/phpstan-src/vendor/nette/neon/src/Neon/Node/ArrayItemNode.php(63): Nette\Neon\Node\StringNode->toString()
#1 /Users/staabm/workspace/phpstan-src/vendor/nette/neon/src/Neon/Node/BlockArrayNode.php(32): Nette\Neon\Node\ArrayItemNode::itemsToBlockString(Array)
#2 /Users/staabm/workspace/phpstan-src/vendor/nette/neon/src/Neon/Node/ArrayItemNode.php(63): Nette\Neon\Node\BlockArrayNode->toString()
#3 /Users/staabm/workspace/phpstan-src/vendor/nette/neon/src/Neon/Node/BlockArrayNode.php(32): Nette\Neon\Node\ArrayItemNode::itemsToBlockString(Array)
#4 /Users/staabm/workspace/phpstan-src/vendor/nette/neon/src/Neon/Node/ArrayItemNode.php(63): Nette\Neon\Node\BlockArrayNode->toString()
#5 /Users/staabm/workspace/phpstan-src/vendor/nette/neon/src/Neon/Node/BlockArrayNode.php(32): Nette\Neon\Node\ArrayItemNode::itemsToBlockString(Array)
#6 /Users/staabm/workspace/phpstan-src/vendor/nette/neon/src/Neon/Node/ArrayItemNode.php(63): Nette\Neon\Node\BlockArrayNode->toString()
#7 /Users/staabm/workspace/phpstan-src/vendor/nette/neon/src/Neon/Node/BlockArrayNode.php(32): Nette\Neon\Node\ArrayItemNode::itemsToBlockString(Array)
#8 /Users/staabm/workspace/phpstan-src/vendor/nette/neon/src/Neon/Encoder.php(35): Nette\Neon\Node\BlockArrayNode->toString()
#9 /Users/staabm/workspace/phpstan-src/vendor/nette/neon/src/Neon/Neon.php(32): Nette\Neon\Encoder->encode(Array)
#10 /Users/staabm/workspace/phpstan-src/src/Command/ErrorFormatter/BaselineNeonErrorFormatter.php(76): Nette\Neon\Neon::encode(Array, true)

@staabm staabm changed the title Reproduce bug 12629 Generated baseline can't be used if regex can't be compilated to UTF-8 chars Feb 22, 2025
@staabm staabm marked this pull request as ready for review February 22, 2025 11:26
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

path: src/bug-12629.php

-
message: '#^Regex pattern is invalid\: Compilation failed\: UTF\-8 error\: byte 2 top bits not 0x80 at offset 0 in pattern$#'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

before this fix this error message had the invalid pattern appended, which made the parser crash while loading the baseline later on

@staabm
Copy link
Contributor Author

staabm commented Feb 22, 2025

(sorry for too many pushes. trial and error debugging in github actions is sometimes not avoidable)

@ondrejmirtes
Copy link
Member

I feel like this can happen in any rule that will report something about a ConstantStringType and prints it with VerbosityLevel::value().

This needs a fix in the neon library directly, or when encoding/decoding the value.

Maybe in ConstantStringType::describe(). Not sure.

@staabm
Copy link
Contributor Author

staabm commented Feb 23, 2025

I just found nette/neon#72 in which there was a similar discussion with other control characters.
will investigate. opened a new upstream issue in nette/neon#76

@staabm staabm marked this pull request as draft March 1, 2025 15:12
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.

3 participants