Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.

Commit 97a8868

Browse files
committed
bug #278 Fix lowercase issues with unicode characters (Pierstoval, javiereguiluz)
This PR was merged into the 1.0-dev branch. Discussion ---------- Fix lowercase issues with unicode characters @Pierstoval I tried your proposal in #197 but it didn't work for me. This new PR proposes to fix most of the errors for European languages. Sadly it won't work for Japanese, Chinese, Arabic, Hebrew, etc. Commits ------- 19b6799 Missing EOL 74d991b Clean the package names using the same regexp as Composer 4773869 Finished this feature e1de703 Try to fix #190 by fixing lowercase package name
2 parents dd59a04 + 19b6799 commit 97a8868

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

src/Symfony/Installer/NewCommand.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,14 @@ protected function generateComposerProjectName()
378378
*/
379379
private function fixComposerPackageName($name)
380380
{
381-
return strtolower(
382-
preg_replace(
383-
array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'),
384-
array('\\1-\\2', '\\1-\\2'),
385-
strtr($name, '-', '.')
386-
)
381+
$name = str_replace(
382+
['à', 'á', 'â', 'ä', 'æ', 'ã', 'å', 'ā', 'é', 'è', 'ê', 'ë', 'ę', 'ė', 'ē', 'ī', 'į', 'í', 'ì', 'ï', 'î', 'ō', 'ø', 'œ', 'õ', 'ó', 'ò', 'ö', 'ô', 'ū', 'ú', 'ù', 'ü', 'û', 'ç', 'ć', 'č', 'ł', 'ñ', 'ń', 'ß', 'ś', 'š', 'ŵ', 'ŷ', 'ÿ', 'ź', 'ž', 'ż'],
383+
['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'i', 'i', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'u', 'c', 'c', 'c', 'l', 'n', 'n', 's', 's', 's', 'w', 'y', 'y', 'z', 'z', 'z'],
384+
$name
387385
);
386+
$name = preg_replace('#[^A-Za-z0-9_./-]+#', '', $name);
387+
388+
return strtolower($name);
388389
}
389390

390391
/**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Symfony\Installer\Tests;
4+
5+
use Symfony\Installer\NewCommand;
6+
7+
class NewCommandTest extends \PHPUnit_Framework_TestCase
8+
{
9+
/**
10+
* @dataProvider getProjectNames
11+
*/
12+
public function testFixComposerPackageName($originalName, $expectedName)
13+
{
14+
$command = new NewCommand();
15+
$method = new \ReflectionMethod($command, 'fixComposerPackageName');
16+
$method->setAccessible(true);
17+
18+
$fixedName = $method->invoke($command, $originalName);
19+
$this->assertSame($expectedName, $fixedName);
20+
}
21+
22+
public function getProjectNames()
23+
{
24+
return [
25+
['foo/bar', 'foo/bar'],
26+
['áèî/øū', 'aei/ou'],
27+
['çñß/łŵž', 'cns/lwz'],
28+
['foo#bar\foo?bar=foo!bar{foo]bar', 'foobarfoobarfoobarfoobar'],
29+
['FOO/bar', 'foo/bar'],
30+
];
31+
}
32+
}

0 commit comments

Comments
 (0)