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

Fix lowercase issues with unicode characters #278

Merged
merged 4 commits into from
Oct 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/Symfony/Installer/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,14 @@ protected function generateComposerProjectName()
*/
private function fixComposerPackageName($name)
{
return strtolower(
preg_replace(
array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'),
array('\\1-\\2', '\\1-\\2'),
strtr($name, '-', '.')
)
$name = str_replace(
['à', 'á', 'â', 'ä', 'æ', 'ã', 'å', 'ā', 'é', 'è', 'ê', 'ë', 'ę', 'ė', 'ē', 'ī', 'į', 'í', 'ì', 'ï', 'î', 'ō', 'ø', 'œ', 'õ', 'ó', 'ò', 'ö', 'ô', 'ū', 'ú', 'ù', 'ü', 'û', 'ç', 'ć', 'č', 'ł', 'ñ', 'ń', 'ß', 'ś', 'š', 'ŵ', 'ŷ', 'ÿ', 'ź', 'ž', 'ż'],
['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'],
$name
);
$name = preg_replace('#[^A-Za-z0-9_./-]+#', '', $name);

return strtolower($name);
}

protected function getDownloadedApplicationType()
Expand Down
32 changes: 32 additions & 0 deletions tests/Symfony/Installer/Tests/NewCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Symfony\Installer\Tests;

use Symfony\Installer\NewCommand;

class NewCommandTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider getProjectNames
*/
public function testFixComposerPackageName($originalName, $expectedName)
{
$command = new NewCommand();
$method = new \ReflectionMethod($command, 'fixComposerPackageName');
$method->setAccessible(true);

$fixedName = $method->invoke($command, $originalName);
$this->assertSame($expectedName, $fixedName);
}

public function getProjectNames()
{
return [
['foo/bar', 'foo/bar'],
['áèî/øū', 'aei/ou'],
['çñß/łŵž', 'cns/lwz'],
['foo#bar\foo?bar=foo!bar{foo]bar', 'foobarfoobarfoobarfoobar'],
['FOO/bar', 'foo/bar'],
];
}
}