8000 [HttpKernel] Fixed name resolution when the parent directory contain … · symfony/symfony@819d104 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 819d104

Browse files
committed
[HttpKernel] Fixed name resolution when the parent directory contain fordidden char for a class name
1 parent 760ad33 commit 819d104

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public function locateResource($name, $dir = null, $first = true)
308308
public function getName()
309309
{
310310
if (null === $this->name) {
311-
$this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
311+
$this->name = preg_replace('/(^[0-9]*|[^a-zA-Z0-9_]+)/', '', basename($this->rootDir)) ?: 'app';
312312
}
313313

314314
return $this->name;

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,31 @@ public function testGetName()
386386
$this->assertEquals('Fixtures', $kernel->getName());
387387
}
388388

389+
public function getGetNameWithWeirdDirectoryTests()
390+
{
391+
return array(
392+
array('app', 12345),
393+
array('Application', '12345Application'),
394+
array('Application12345', 'Application12345'),
395+
array('Application12345', '12345Application12345'),
396+
);
397+
}
398+
399+
/** @dataProvider getGetNameWithWeirdDirectoryTests */
400+
public function testGetNameWithWeirdDirectory($expected, $rootDir)
401+
{
402+
$kernel = new KernelForTest('test', true);
403+
$p = new \ReflectionProperty($kernel, 'rootDir');
404+
$p->setAccessible(true);
405+
$p->setValue($kernel, $rootDir);
406+
407+
$p = new \ReflectionProperty($kernel, 'name');
408+
$p->setAccessible(true);
409+
$p->setValue($kernel, null);
410+
411+
$this->assertEquals($expected, $kernel->getName());
412+
}
413+
389414
public function testOverrideGetName()
390415
{
391416
$kernel = new KernelForOverrideName('test', true);

0 commit comments

Comments
 (0)
0