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:
commit
0544b1f594
@ -106,6 +106,13 @@ class ORMQueryBuilderLoader implements EntityLoaderInterface
|
|||||||
$values = array_values(array_filter($values, function ($v) {
|
$values = array_values(array_filter($values, function ($v) {
|
||||||
return (string) $v === (string) (int) $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 {
|
} else {
|
||||||
$parameterType = Connection::PARAM_STR_ARRAY;
|
$parameterType = Connection::PARAM_STR_ARRAY;
|
||||||
}
|
}
|
||||||
|
@ -229,8 +229,11 @@ class Crawler extends \SplObjectStorage
|
|||||||
*
|
*
|
||||||
* @param string $content The XML content
|
* @param string $content The XML content
|
||||||
* @param string $charset The charset
|
* @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
|
// remove the default namespace if it's the only namespace to make XPath expressions simpler
|
||||||
if (!preg_match('/xmlns:/', $content)) {
|
if (!preg_match('/xmlns:/', $content)) {
|
||||||
@ -244,7 +247,7 @@ class Crawler extends \SplObjectStorage
|
|||||||
$dom->validateOnParse = true;
|
$dom->validateOnParse = true;
|
||||||
|
|
||||||
if ('' !== trim($content)) {
|
if ('' !== trim($content)) {
|
||||||
@$dom->loadXML($content, LIBXML_NONET | (defined('LIBXML_PARSEHUGE') ? LIBXML_PARSEHUGE : 0));
|
@$dom->loadXML($content, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
libxml_use_internal_errors($internalErrors);
|
libxml_use_internal_errors($internalErrors);
|
||||||
|
@ -158,26 +158,23 @@ class Filesystem
|
|||||||
$files = iterator_to_array($this->toIterator($files));
|
$files = iterator_to_array($this->toIterator($files));
|
||||||
$files = array_reverse($files);
|
$files = array_reverse($files);
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
if (!$this->exists($file) && !is_link($file)) {
|
if (is_link($file)) {
|
||||||
continue;
|
// Workaround https://bugs.php.net/52176
|
||||||
}
|
if (!@unlink($file) && !@rmdir($file)) {
|
||||||
|
$error = error_get_last();
|
||||||
if (is_dir($file) && !is_link($file)) {
|
throw new IOException(sprintf('Failed to remove symlink "%s": %s.', $file, $error['message']));
|
||||||
|
}
|
||||||
|
} elseif (is_dir($file)) {
|
||||||
$this->remove(new \FilesystemIterator($file));
|
$this->remove(new \FilesystemIterator($file));
|
||||||
|
|
||||||
if (true !== @rmdir($file)) {
|
if (!@rmdir($file)) {
|
||||||
throw new IOException(sprintf('Failed to remove directory "%s".', $file), 0, null, $file);
|
$error = error_get_last();
|
||||||
|
throw new IOException(sprintf('Failed to remove directory "%s": %s.', $file, $error['message']));
|
||||||
}
|
}
|
||||||
} else {
|
} elseif ($this->exists($file)) {
|
||||||
// https://bugs.php.net/bug.php?id=52176
|
if (!@unlink($file)) {
|
||||||
if ('\\' === DIRECTORY_SEPARATOR && is_dir($file)) {
|
$error = error_get_last();
|
||||||
if (true !== @rmdir($file)) {
|
throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message']));
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -308,10 +305,15 @@ class Filesystem
|
|||||||
*/
|
*/
|
||||||
public function symlink($originDir, $targetDir, $copyOnWindows = false)
|
public function symlink($originDir, $targetDir, $copyOnWindows = false)
|
||||||
{
|
{
|
||||||
if ('\\' === DIRECTORY_SEPARATOR && $copyOnWindows) {
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||||
$this->mirror($originDir, $targetDir);
|
$originDir = strtr($originDir, '/', '\\');
|
||||||
|
$targetDir = strtr($targetDir, '/', '\\');
|
||||||
|
|
||||||
return;
|
if ($copyOnWindows) {
|
||||||
|
$this->mirror($originDir, $targetDir);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->mkdir(dirname($targetDir));
|
$this->mkdir(dirname($targetDir));
|
||||||
|
@ -278,7 +278,7 @@ class FilesystemTest extends FilesystemTestCase
|
|||||||
|
|
||||||
$this->filesystem->remove($basePath);
|
$this->filesystem->remove($basePath);
|
||||||
|
|
||||||
$this->assertTrue(!is_dir($basePath));
|
$this->assertFileNotExists($basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveCleansArrayOfFilesAndDirectories()
|
public function testRemoveCleansArrayOfFilesAndDirectories()
|
||||||
@ -294,8 +294,8 @@ class FilesystemTest extends FilesystemTestCase
|
|||||||
|
|
||||||
$this->filesystem->remove($files);
|
$this->filesystem->remove($files);
|
||||||
|
|
||||||
$this->assertTrue(!is_dir($basePath.'dir'));
|
$this->assertFileNotExists($basePath.'dir');
|
||||||
$this->assertTrue(!is_file($basePath.'file'));
|
$this->assertFileNotExists($basePath.'file');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveCleansTraversableObjectOfFilesAndDirectories()
|
public function testRemoveCleansTraversableObjectOfFilesAndDirectories()
|
||||||
@ -311,8 +311,8 @@ class FilesystemTest extends FilesystemTestCase
|
|||||||
|
|
||||||
$this->filesystem->remove($files);
|
$this->filesystem->remove($files);
|
||||||
|
|
||||||
$this->assertTrue(!is_dir($basePath.'dir'));
|
$this->assertFileNotExists($basePath.'dir');
|
||||||
$this->assertTrue(!is_file($basePath.'file'));
|
$this->assertFileNotExists($basePath.'file');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveIgnoresNonExistingFiles()
|
public function testRemoveIgnoresNonExistingFiles()
|
||||||
@ -327,7 +327,7 @@ class FilesystemTest extends FilesystemTestCase
|
|||||||
|
|
||||||
$this->filesystem->remove($files);
|
$this->filesystem->remove($files);
|
||||||
|
|
||||||
$this->assertTrue(!is_dir($basePath.'dir'));
|
$this->assertFileNotExists($basePath.'dir');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveCleansInvalidLinks()
|
public function testRemoveCleansInvalidLinks()
|
||||||
@ -339,11 +339,19 @@ class FilesystemTest extends FilesystemTestCase
|
|||||||
mkdir($basePath);
|
mkdir($basePath);
|
||||||
mkdir($basePath.'dir');
|
mkdir($basePath.'dir');
|
||||||
// create symlink to nonexistent file
|
// 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->filesystem->remove($basePath);
|
||||||
|
|
||||||
$this->assertTrue(!is_dir($basePath));
|
$this->assertFileNotExists($basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFilesExists()
|
public function testFilesExists()
|
||||||
|
@ -1566,6 +1566,13 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(80, $request->getPort());
|
$this->assertEquals(80, $request->getPort());
|
||||||
$this->assertFalse($request->isSecure());
|
$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()
|
// trusted proxy via setTrustedProxies()
|
||||||
Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2'));
|
Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2'));
|
||||||
$this->assertEquals('1.1.1.1', $request->getClientIp());
|
$this->assertEquals('1.1.1.1', $request->getClientIp());
|
||||||
|
Reference in New Issue
Block a user