Merge branch '2.3' into 2.7

* 2.3:
  [DomCrawler] Dont use LIBXML_PARSEHUGE by default
  [Filesystem] Reduce complexity of ->remove()
  added tests for non-trusted proxies
  add 'guid' to list of exception to filter out
  Ensure backend slashes for symlinks on Windows systems
  [Filesystem] Try to delete broken symlinks
This commit is contained in:
Fabien Potencier 2016-03-02 16:25:10 +01:00
commit 0544b1f594
5 changed files with 57 additions and 30 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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));

View File

@ -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()

View File

@ -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());