Skip to content

Commit c10f602

Browse files
committed
bug #1444 [StimulusBundle] Handles Windows directory separator when normalizing controller names (tamcy)
This PR was merged into the 2.x branch. Discussion ---------- [StimulusBundle] Handles Windows directory separator when normalizing controller names | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Issues | Fix #1422 | License | MIT This fixes the issue that controller name normalization doesn't work as intended in Windows which uses `\` as the directory separator. In fact, without the fix, PHPUnit fails when running on Windows platform with the following error: ``` 1) Symfony\UX\StimulusBundle\Tests\AssetMapper\ControllerMapGeneratorTest::testGetControllersMap Failed asserting that two arrays are identical. --- Expected +++ Actual @@ @@ 4 => 'hello-with-dashes' 5 => 'hello-with-underscores' 6 => 'other' - 7 => 'subdir--deeper' - 8 => 'subdir--deeper-with-dashes' - 9 => 'subdir--deeper-with-underscores' + 7 => 'subdir\deeper' + 8 => 'subdir\deeper-with-dashes' + 9 => 'subdir\deeper-with-underscores' 10 => 'typescript' ) ``` Commits ------- 41d2cbc [StimulusBundle] Handles Windows directory separator when normalizing controller names (fixes #1422)
2 parents 5a37a3e + 41d2cbc commit c10f602

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/StimulusBundle/src/AssetMapper/ControllersMapGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private function loadCustomControllers(): array
7676
// use regex to extract 'controller'-postfix including extension
7777
preg_match(self::FILENAME_REGEX, $name, $matches);
7878
$name = str_replace(['_'.$matches[1], '-'.$matches[1]], '', $name);
79-
$name = str_replace(['_', '/'], ['-', '--'], $name);
79+
$name = str_replace(['_', '/', '\\'], ['-', '--', '--'], $name);
8080

8181
$asset = $this->assetMapper->getAssetFromSourcePath($file->getRealPath());
8282
$content = $asset->content ?: file_get_contents($asset->sourcePath);

0 commit comments

Comments
 (0)