8000 [HttpKernel] Fixed Kernel::getContainerClass, to prevent invalid PHP class name by lyrixx · Pull Request #13412 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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

Closed
wants to merge 2 commits into from

Conversation

lyrixx
Copy link
Member
@lyrixx lyrixx commented Jan 14, 2015
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc 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 the getName method, or only the getContainerClass().
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 ;)

@lyrixx lyrixx changed the title [HttpKernel] Fixed name resolution when the parent directory contain fordidden char for a class name [HttpKernel] Fixed Kernel::getContainerClass, to prevent invalid PHP class name Jan 14, 2015
@lyrixx lyrixx force-pushed the fix-kernel-get-name branch 2 times, most recently from a43c1c8 to a9c1bcc Compare January 14, 2015 19:20
@lyrixx lyrixx force-pushed the fix-kernel-get-name branch from a9c1bcc to d86c404 Compare January 14, 2015 23:28
jderusse added a commit to sensiolabs/melody that referenced this pull request Jan 15, 2015
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 $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer';
return preg_replace('/(^[0-9]*|[^a-zA-Z0-9_]+)/', '', $this->name.ucfirst($this->environment)).($this->debug ? 'Debug' : '').'ProjectContainer';
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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)

Copy link
Member Author

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

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
0