-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpKernel] Fixed Kernel::getContainerClass, to prevent invalid PHP class name #13412
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
…fordidden char for a class name
a43c1c8
to
a9c1bcc
Compare
a9c1bcc
to
d86c404
Compare
This PR was merged into the master branch. Discussion ---------- Prefix the working directory hash to avoid weird issue Some application use `basename(__DIR__)` and may generate class name with this dirname. And a sha256 hash may start with a number. This will lead to a fatal error because PHP forbid that. see symfony/symfony#13412 for a related issue Commits ------- a72b7a6 Prefix the working directory hash to avoid weird issue
@@ -502,7 +502,7 @@ protected function initializeBundles() | |||
*/ | |||
protected function getContainerClass() | |||
{ | |||
|
|||
return preg_replace('/(^[0-9]*|[^a-zA-Z0-9_]+)/', '', $this->name.ucfirst($this->environment)).($this->debug ? 'Debug' : '').'ProjectContainer'; |
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.
If I have the following 3 applications, will it still work after this change? Wouldn't it be better to just prefix something?
1app
2app
3app
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.
Good point. But right now, this "feature" is not supported.
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.
I don't think we need to support these edge cases... especially now that Melody has been fixed. it adds a regex for every single request and makes the code less readable.
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.
thus, if we fix it here, we need to fix it for the other dumped classes (the url matcher and the url generator)
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.
ok. no problem. I close the PR
If the folder which contains the kernel begin with a number, symfony will crash because symfony will create a container class starting with a number.
I'm not sure if I should fix thegetName
method, or only thegetContainerClass()
.More over, if the
environment
contains some invalid characters, it should be fixed too.Actually, I sanitaze only the
getContainerClass
method. I did not squashed my commit if I need to revert ;)