Skip to content

Commit d8e0887

Browse files
[DI] tighten detection of local dirs to prevent false positives
1 parent e39380b commit d8e0887

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

Dumper/PhpDumper.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function dump(array $options = [])
191191
$regex = preg_quote(\DIRECTORY_SEPARATOR.$dir[$i], '#').$regex;
192192
} while (0 < --$i);
193193

194-
$this->targetDirRegex = '#'.preg_quote($dir[0], '#').$regex.'#';
194+
$this->targetDirRegex = '#(^|file://|[:;, \|\r\n])'.preg_quote($dir[0], '#').$regex.'#';
195195
}
196196
}
197197

@@ -1993,11 +1993,12 @@ private function isHotPath(Definition $definition)
19931993
private function export($value)
19941994
{
19951995
if (null !== $this->targetDirRegex && \is_string($value) && preg_match($this->targetDirRegex, $value, $matches, PREG_OFFSET_CAPTURE)) {
1996-
$prefix = $matches[0][1] ? $this->doExport(substr($value, 0, $matches[0][1]), true).'.' : '';
19971996
$suffix = $matches[0][1] + \strlen($matches[0][0]);
1997+
$matches[0][1] += \strlen($matches[1][0]);
1998+
$prefix = $matches[0][1] ? $this->doExport(substr($value, 0, $matches[0][1]), true).'.' : '';
19981999
$suffix = isset($value[$suffix]) ? '.'.$this->doExport(substr($value, $suffix), true) : '';
19992000
$dirname = $this->asFiles ? '$this->containerDir' : '__DIR__';
2000-
$offset = 1 + $this->targetDirMaxMatches - \count($matches);
2001+
$offset = 2 + $this->targetDirMaxMatches - \count($matches);
20012002

20022003
if ($this->asFiles || 0 < $offset) {
20032004
$dirname = sprintf('$this->targetDirs[%d]', $offset);

Tests/Dumper/PhpDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function testDumpRelativeDir()
9898

9999
$container = new ContainerBuilder();
100100
$container->setDefinition('test', $definition);
101-
$container->setParameter('foo', 'wiz'.\dirname(__DIR__));
101+
$container->setParameter('foo', 'file://'.\dirname(__DIR__));
102102
$container->setParameter('bar', __DIR__);
103103
$container->setParameter('baz', '%bar%/PhpDumperTest.php');
104104
$container->setParameter('buz', \dirname(\dirname(__DIR__)));

Tests/Fixtures/php/services12.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function isFrozen()
6767
*/
6868
protected function getTestService()
6969
{
70-
return $this->services['test'] = new \stdClass(('wiz'.$this->targetDirs[1]), [('wiz'.$this->targetDirs[1]) => ($this->targetDirs[2].'/')]);
70+
return $this->services['test'] = new \stdClass(('file://'.$this->targetDirs[1]), [('file://'.$this->targetDirs[1]) => ($this->targetDirs[2].'/')]);
7171
}
7272

7373
public function getParameter($name)
@@ -131,7 +131,7 @@ public function getParameterBag()
131131
private function getDynamicParameter($name)
132132
{
133133
switch ($name) {
134-
case 'foo': $value = ('wiz'.$this->targetDirs[1]); break;
134+
case 'foo': $value = ('file://'.$this->targetDirs[1]); break;
135135
case 'buz': $value = $this->targetDirs[2]; break;
136136
default: throw new InvalidArgumentException(sprintf('The dynamic parameter "%s" must be defined.', $name));
137137
}

0 commit comments

Comments
 (0)