diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php index dae4bb0919..3c5bd17000 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php @@ -106,6 +106,13 @@ class ORMQueryBuilderLoader implements EntityLoaderInterface $values = array_values(array_filter($values, function ($v) { return (string) $v === (string) (int) $v; })); + } elseif ('guid' === $metadata->getTypeOfField($identifier)) { + $parameterType = Connection::PARAM_STR_ARRAY; + + // Like above, but we just filter out empty strings. + $values = array_values(array_filter($values, function ($v) { + return (string) $v !== ''; + })); } else { $parameterType = Connection::PARAM_STR_ARRAY; } diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index 03382db568..9f8259ecb1 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -229,8 +229,11 @@ class Crawler extends \SplObjectStorage * * @param string $content The XML content * @param string $charset The charset + * @param int $options Bitwise OR of the libxml option constants + * LIBXML_PARSEHUGE is dangerous, see + * http://symfony.com/blog/security-release-symfony-2-0-17-released */ - public function addXmlContent($content, $charset = 'UTF-8') + public function addXmlContent($content, $charset = 'UTF-8', $options = LIBXML_NONET) { // remove the default namespace if it's the only namespace to make XPath expressions simpler if (!preg_match('/xmlns:/', $content)) { @@ -244,7 +247,7 @@ class Crawler extends \SplObjectStorage $dom->validateOnParse = true; if ('' !== trim($content)) { - @$dom->loadXML($content, LIBXML_NONET | (defined('LIBXML_PARSEHUGE') ? LIBXML_PARSEHUGE : 0)); + @$dom->loadXML($content, $options); } libxml_use_internal_errors($internalErrors); diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index a3fdb943e0..785c7a0922 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -158,26 +158,23 @@ class Filesystem $files = iterator_to_array($this->toIterator($files)); $files = array_reverse($files); foreach ($files as $file) { - if (!$this->exists($file) && !is_link($file)) { - continue; - } - - if (is_dir($file) && !is_link($file)) { + 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'])); + } + } elseif (is_dir($file)) { $this->remove(new \FilesystemIterator($file)); - if (true !== @rmdir($file)) { - throw new IOException(sprintf('Failed to remove directory "%s".', $file), 0, null, $file); + if (!@rmdir($file)) { + $error = error_get_last(); + throw new IOException(sprintf('Failed to remove directory "%s": %s.', $file, $error['message'])); } - } else { - // https://bugs.php.net/bug.php?id=52176 - if ('\\' === DIRECTORY_SEPARATOR && is_dir($file)) { - if (true !== @rmdir($file)) { - throw new IOException(sprintf('Failed to remove file "%s".', $file), 0, null, $file); - } - } else { - if (true !== @unlink($file)) { - throw new IOException(sprintf('Failed to remove file "%s".', $file), 0, null, $file); - } + } elseif ($this->exists($file)) { + if (!@unlink($file)) { + $error = error_get_last(); + throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message'])); } } } @@ -308,10 +305,15 @@ class Filesystem */ public function symlink($originDir, $targetDir, $copyOnWindows = false) { - if ('\\' === DIRECTORY_SEPARATOR && $copyOnWindows) { - $this->mirror($originDir, $targetDir); + if ('\\' === DIRECTORY_SEPARATOR) { + $originDir = strtr($originDir, '/', '\\'); + $targetDir = strtr($targetDir, '/', '\\'); - return; + if ($copyOnWindows) { + $this->mirror($originDir, $targetDir); + + return; + } } $this->mkdir(dirname($targetDir)); diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 75fd880cc9..579329a5fc 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -278,7 +278,7 @@ class FilesystemTest extends FilesystemTestCase $this->filesystem->remove($basePath); - $this->assertTrue(!is_dir($basePath)); + $this->assertFileNotExists($basePath); } public function testRemoveCleansArrayOfFilesAndDirectories() @@ -294,8 +294,8 @@ class FilesystemTest extends FilesystemTestCase $this->filesystem->remove($files); - $this->assertTrue(!is_dir($basePath.'dir')); - $this->assertTrue(!is_file($basePath.'file')); + $this->assertFileNotExists($basePath.'dir'); + $this->assertFileNotExists($basePath.'file'); } public function testRemoveCleansTraversableObjectOfFilesAndDirectories() @@ -311,8 +311,8 @@ class FilesystemTest extends FilesystemTestCase $this->filesystem->remove($files); - $this->assertTrue(!is_dir($basePath.'dir')); - $this->assertTrue(!is_file($basePath.'file')); + $this->assertFileNotExists($basePath.'dir'); + $this->assertFileNotExists($basePath.'file'); } public function testRemoveIgnoresNonExistingFiles() @@ -327,7 +327,7 @@ class FilesystemTest extends FilesystemTestCase $this->filesystem->remove($files); - $this->assertTrue(!is_dir($basePath.'dir')); + $this->assertFileNotExists($basePath.'dir'); } public function testRemoveCleansInvalidLinks() @@ -339,11 +339,19 @@ class FilesystemTest extends FilesystemTestCase mkdir($basePath); mkdir($basePath.'dir'); // create symlink to nonexistent file - @symlink($basePath.'file', $basePath.'link'); + @symlink($basePath.'file', $basePath.'file-link'); + + // create symlink to dir using trailing forward slash + $this->filesystem->symlink($basePath.'dir/', $basePath.'dir-link'); + $this->assertTrue(is_dir($basePath.'dir-link')); + + // create symlink to nonexistent dir + rmdir($basePath.'dir'); + $this->assertFalse(is_dir($basePath.'dir-link')); $this->filesystem->remove($basePath); - $this->assertTrue(!is_dir($basePath)); + $this->assertFileNotExists($basePath); } public function testFilesExists() diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 39bf69fc43..ba2b188093 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -1566,6 +1566,13 @@ class RequestTest extends \PHPUnit_Framework_TestCase $this->assertEquals(80, $request->getPort()); $this->assertFalse($request->isSecure()); + // request is forwarded by a non-trusted proxy + Request::setTrustedProxies(array('2.2.2.2')); + $this->assertEquals('3.3.3.3', $request->getClientIp()); + $this->assertEquals('example.com', $request->getHost()); + $this->assertEquals(80, $request->getPort()); + $this->assertFalse($request->isSecure()); + // trusted proxy via setTrustedProxies() Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2')); $this->assertEquals('1.1.1.1', $request->getClientIp());