From fbb12d89d19214cd014adab69782f7bab8fd85f4 Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Mon, 7 Mar 2016 16:40:05 +0000 Subject: [PATCH 1/2] [Validator] Fix the locale validator so it treats a locale alias as a valid locale --- .../Component/Validator/Constraints/LocaleValidator.php | 3 ++- .../Validator/Tests/Constraints/LocaleValidatorTest.php | 1 + src/Symfony/Component/Validator/composer.json | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/LocaleValidator.php b/src/Symfony/Component/Validator/Constraints/LocaleValidator.php index f54ef93565..7397a64c4a 100644 --- a/src/Symfony/Component/Validator/Constraints/LocaleValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LocaleValidator.php @@ -38,8 +38,9 @@ class LocaleValidator extends ConstraintValidator $value = (string) $value; $locales = Intl::getLocaleBundle()->getLocaleNames(); + $aliases = Intl::getLocaleBundle()->getAliases(); - if (!isset($locales[$value])) { + if (!isset($locales[$value]) && !in_array($value, $aliases)) { $this->context->addViolation($constraint->message, array( '{{ value }}' => $this->formatValue($value), )); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php index e93ee80e52..4872d47164 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php @@ -61,6 +61,7 @@ class LocaleValidatorTest extends AbstractConstraintValidatorTest array('pt'), array('pt_PT'), array('zh_Hans'), + array('fil_PH'), ); } diff --git a/src/Symfony/Component/Validator/composer.json b/src/Symfony/Component/Validator/composer.json index ea79565660..2d473162a6 100644 --- a/src/Symfony/Component/Validator/composer.json +++ b/src/Symfony/Component/Validator/composer.json @@ -22,7 +22,7 @@ "require-dev": { "doctrine/common": "~2.3", "symfony/http-foundation": "~2.1", - "symfony/intl": "~2.3", + "symfony/intl": "^2.3.21", "symfony/yaml": "~2.0,>=2.0.5", "symfony/config": "~2.2" }, From 3efd900565f1f277753139bf45f41bf65aef2559 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 8 Mar 2016 08:38:51 +0100 Subject: [PATCH 2/2] [Filesystem] Fix false positive in ->remove() --- .../Component/Filesystem/Filesystem.php | 23 +++++++++---------- .../Filesystem/Tests/FilesystemTest.php | 19 +++++++-------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 333a70689b..d800bd72fc 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -143,12 +143,13 @@ class Filesystem $files = iterator_to_array($this->toIterator($files)); $files = array_reverse($files); foreach ($files as $file) { + if (@(unlink($file) || rmdir($file))) { + continue; + } if (is_link($file)) { - // Workaround https://bugs.php.net/52176 - if (!@unlink($file) && !@rmdir($file)) { - $error = error_get_last(); - throw new IOException(sprintf('Failed to remove symlink "%s": %s.', $file, $error['message'])); - } + // See https://bugs.php.net/52176 + $error = error_get_last(); + throw new IOException(sprintf('Failed to remove symlink "%s": %s.', $file, $error['message'])); } elseif (is_dir($file)) { $this->remove(new \FilesystemIterator($file)); @@ -156,11 +157,9 @@ class Filesystem $error = error_get_last(); throw new IOException(sprintf('Failed to remove directory "%s": %s.', $file, $error['message'])); } - } elseif ($this->exists($file)) { - if (!@unlink($file)) { - $error = error_get_last(); - throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message'])); - } + } elseif (file_exists($file)) { + $error = error_get_last(); + throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message'])); } } } @@ -403,7 +402,7 @@ class Filesystem } $copyOnWindows = false; - if (isset($options['copy_on_windows']) && !function_exists('symlink')) { + if (isset($options['copy_on_windows'])) { $copyOnWindows = $options['copy_on_windows']; } @@ -420,7 +419,7 @@ class Filesystem $target = str_replace($originDir, $targetDir, $file->getPathname()); if ($copyOnWindows) { - if (is_link($file) || is_file($file)) { + if (is_file($file)) { $this->copy($file, $target, isset($options['override']) ? $options['override'] : false); } elseif (is_dir($file)) { $this->mkdir($target); diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 867ed737a7..ff27f4cebc 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -38,10 +38,8 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase if ('\\' === DIRECTORY_SEPARATOR && null === self::$symlinkOnWindows) { $target = tempnam(sys_get_temp_dir(), 'sl'); $link = sys_get_temp_dir().'/sl'.microtime(true).mt_rand(); - if (@symlink($target, $link)) { - self::$symlinkOnWindows = @is_link($link); - unlink($link); - } + self::$symlinkOnWindows = @symlink($target, $link) && is_link($link); + @unlink($link); unlink($target); } } @@ -61,6 +59,7 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase foreach ($this->longPathNamesWindows as $path) { exec('DEL '.$path); } + $this->longPathNamesWindows = array(); } $this->filesystem->remove($this->workspace); @@ -350,7 +349,7 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase // create symlink to nonexistent dir rmdir($basePath.'dir'); - $this->assertFalse(is_dir($basePath.'dir-link')); + $this->assertFalse('\\' === DIRECTORY_SEPARATOR ? @readlink($basePath.'dir-link') : is_dir($basePath.'dir-link')); $this->filesystem->remove($basePath); @@ -742,6 +741,8 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase $this->filesystem->remove($link); $this->assertTrue(!is_link($link)); + $this->assertTrue(!is_file($link)); + $this->assertTrue(!is_dir($link)); } public function testSymlinkIsOverwrittenIfPointsToDifferentTarget() @@ -915,7 +916,7 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase $this->filesystem->mirror($sourcePath, $targetPath); $this->assertTrue(is_dir($targetPath)); - $this->assertFileEquals($sourcePath.'file1', $targetPath.DIRECTORY_SEPARATOR.'link1'); + $this->assertFileEquals($sourcePath.'file1', $targetPath.'link1'); $this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1')); } @@ -935,7 +936,7 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase $this->filesystem->mirror($sourcePath, $targetPath); $this->assertTrue(is_dir($targetPath)); - $this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.DIRECTORY_SEPARATOR.'link1/file1.txt'); + $this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.'link1/file1.txt'); $this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1')); } @@ -959,7 +960,7 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase $this->filesystem->mirror($sourcePath, $targetPath); $this->assertTrue(is_dir($targetPath)); - $this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.DIRECTORY_SEPARATOR.'link1/file1.txt'); + $this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.'link1/file1.txt'); $this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1')); $this->assertEquals('nested', readlink($targetPath.DIRECTORY_SEPARATOR.'link1')); } @@ -1089,7 +1090,7 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase private function markAsSkippedIfPosixIsMissing() { - if ('\\' === DIRECTORY_SEPARATOR || !function_exists('posix_isatty')) { + if (!function_exists('posix_isatty')) { $this->markTestSkipped('POSIX is not supported'); } }