8000 Merge branch '2.7' into 2.8 · ocical/symfony@ef08c07 · GitHub
[go: up one dir, main page]

Skip to content

Commit ef08c07

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: fixed CS [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 fixed tests [FrameworkBundle] Test that ObjectNormalizer is registered
2 parents fdabbaa + 29c6162 commit ef08c07

File tree

6 files changed

+70
-32
lines changed

6 files changed

+70
-32
lines changed

src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ public function getEntitiesByIds($identifier, array $values)
106106
$values = array_values(array_filter($values, function ($v) {
107107
return (string) $v === (string) (int) $v;
108108
}));
109+
} elseif ('guid' === $metadata->getTypeOfField($identifier)) {
110+
$parameterType = Connection::PARAM_STR_ARRAY;
111+
112+
// Like above, but we just filter out empty strings.
113+
$values = array_values(array_filter($values, function ($v) {
114+
return (string) $v !== '';
115+
}));
109116
} else {
110117
$parameterType = Connection::PARAM_STR_ARRAY;
111118
}

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,17 @@ public function testSerializerEnabled()
457457
$this->assertEquals(new Reference('serializer.name_converter.camel_case_to_snake_case'), $container->getDefinition('serializer.normalizer.object')->getArgument(1));
458458
}
459459

460+
public function testObjectNormalizerRegistered()
461+
{
462+
$container = $this->createContainerFromFile('full');
463+
464+
$definition = $container->getDefinition('serializer.normalizer.object');
465+
$tag = $definition->getTag('serializer.normalizer');
466+
467+
$this->assertEquals('Symfony\Component\Serializer\Normalizer\ObjectNormalizer', $definition->getClass());
468+
$this->assertEquals(-1000, $tag[0]['priority']);
469+
}
470+
460471
public function testAssetHelperWhenAssetsAreEnabled()
461472
{
462473
$container = $this->createContainerFromFile('full');

src/Symfony/Component/DomCrawler/Crawler.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,11 @@ public function addHtmlContent($content, $charset = 'UTF-8')
215215
*
216216
* @param string $content The XML content
217217
* @param string $charset The charset
218+
* @param int $options Bitwise OR of the libxml option constants
219+
* LIBXML_PARSEHUGE is dangerous, see
220+
* http://symfony.com/blog/security-release-symfony-2-0-17-released
218221
*/
219-
public function addXmlContent($content, $charset = 'UTF-8')
222+
public function addXmlContent($content, $charset = 'UTF-8', $options = LIBXML_NONET)
220223
{
221224
// remove the default namespace if it's the only namespace to make XPath expressions simpler
222225
if (!preg_match('/xmlns:/', $content)) {
@@ -230,7 +233,7 @@ public function addXmlContent($content, $charset = 'UTF-8')
230233
$dom->validateOnParse = true;
231234

232235
if ('' !== trim($content)) {
233-
@$dom->loadXML($content, LIBXML_NONET | (defined('LIBXML_PARSEHUGE') ? LIBXML_PARSEHUGE : 0));
236+
@$dom->loadXML($content, $options);
234237
}
235238

236239
libxml_use_internal_errors($internalErrors);

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,26 +158,23 @@ public function remove($files)
158158
$files = iterator_to_array($this->toIterator($files));
159159
$files = array_reverse($files);
160160
foreach ($files as $file) {
161-
if (!$this->exists($file) && !is_link($file)) {
162-
continue;
163-
}
164-
165-
if (is_dir($file) && !is_link($file)) {
161+
if (is_link($file)) {
162+
// Workaround https://bugs.php.net/52176
163+
if (!@unlink($file) && !@rmdir($file)) {
164+
$error = error_get_last();
165+
throw new IOException(sprintf('Failed to remove symlink "%s": %s.', $file, $error['message']));
166+
}
167+
} elseif (is_dir($file)) {
166168
$this->remove(new \FilesystemIterator($file));
167169

168-
if (true !== @rmdir($file)) {
169-
throw new IOException(sprintf('Failed to remove directory "%s".', $file), 0, null, $file);
170+
if (!@rmdir($file)) {
171+
$error = error_get_last();
172+
throw new IOException(sprintf('Failed to remove directory "%s": %s.', $file, $error['message']));
170173
}
171-
} else {
172-
// https://bugs.php.net/bug.php?id=52176
173-
if ('\\' === DIRECTORY_SEPARATOR && is_dir($file)) {
174-
if (true !== @rmdir($file)) {
175-
throw new IOException(sprintf('Failed to remove file "%s".', $file), 0, null, $file);
176-
}
177-
} else {
178-
if (true !== @unlink($file)) {
179-
throw new IOException(sprintf('Failed to remove file "%s".', $file), 0, null, $file);
180-
}
174+
} elseif ($this->exists($file)) {
175+
if (!@unlink($file)) {
176+
$error = error_get_last();
177+
throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message']));
181178
}
182179
}
183180
}
@@ -308,10 +305,15 @@ private function isReadable($filename)
308305
*/
309306
public function symlink($originDir, $targetDir, $copyOnWindows = false)
310307
{
311-
if ('\\' === DIRECTORY_SEPARATOR && $copyOnWindows) {
312-
$this->mirror($originDir, $targetDir);
308+
if ('\\' === DIRECTORY_SEPARATOR) {
309+
$originDir = strtr($originDir, '/', '\\');
310+
$targetDir = strtr($targetDir, '/', '\\');
313311

314-
return;
312+
if ($copyOnWindows) {
313+
$this->mirror($originDir, $targetDir);
314+
315+
return;
316+
}
315317
}
316318

317319
$this->mkdir(dirname($targetDir));

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public function testRemoveCleansFilesAndDirectoriesIteratively()
278278

279279
$this->filesystem->remove($basePath);
280280

281-
$this->assertTrue(!is_dir($basePath));
281+
$this->assertFileNotExists($basePath);
282282
}
283283

284284
public function testRemoveCleansArrayOfFilesAndDirectories()
@@ -294,8 +294,8 @@ public function testRemoveCleansArrayOfFilesAndDirectories()
294294

295295
$this->filesystem->remove($files);
296296

297-
$this->assertTrue(!is_dir($basePath.'dir'));
298-
$this->assertTrue(!is_file($basePath.'file'));
297+
$this->assertFileNotExists($basePath.'dir');
298+
$this->assertFileNotExists($basePath.'file');
299299
}
300300

301301
public function testRemoveCleansTraversableObjectOfFilesAndDirectories()
@@ -311,8 +311,8 @@ public function testRemoveCleansTraversableObjectOfFilesAndDirectories()
311311

312312
$this->filesystem->remove($files);
313313

314-
$this->assertTrue(!is_dir($basePath.'dir'));
315-
$this->assertTrue(!is_file($basePath.'file'));
314+
$this->assertFileNotExists($basePath.'dir');
315+
$this->assertFileNotExists($basePath.'file');
316316
}
317317

318318
public function testRemoveIgnoresNonExistingFiles()
@@ -327,7 +327,7 @@ public function testRemoveIgnoresNonExistingFiles()
327327

328328
$this->filesystem->remove($files);
329329

330-
$this->assertTrue(!is_dir($basePath.'dir'));
330+
$this->assertFileNotExists($basePath.'dir');
331331
}
332332

333333
public function testRemoveCleansInvalidLinks()
@@ -339,11 +339,19 @@ public function testRemoveCleansInvalidLinks()
339339
mkdir($basePath);
340340
mkdir($basePath.'dir');
341341
// create symlink to nonexistent file
342-
@symlink($basePath.'file', $basePath.'link');
342+
@symlink($basePath.'file', $basePath.'file-link');
343+
344+
// create symlink to dir using trailing forward slash
345+
$this->filesystem->symlink($basePath.'dir/', $basePath.'dir-link');
346+
$this->assertTrue(is_dir($basePath.'dir-link'));
347+
348+
// create symlink to nonexistent dir
349+
rmdir($basePath.'dir');
350+
$this->assertFalse(is_dir($basePath.'dir-link'));
343351

344352
$this->filesystem->remove($basePath);
345353

346-
$this->assertTrue(!is_dir($basePath));
354+
$this->assertFileNotExists($basePath);
347355
}
348356

349357
public function testFilesExists()
@@ -1172,8 +1180,8 @@ public function testCopyShouldKeepExecutionPermission()
11721180
{
11731181
$this->markAsSkippedIfChmodIsMissing();
11741182

1175-
$sourceFilePath = $this->workspace . DIRECTORY_SEPARATOR . 'copy_source_file';
1176-
$targetFilePath = $this->workspace . DIRECTORY_SEPARATOR . 'copy_target_file';
1183+
$sourceFilePath = $this->workspace.DIRECTORY_SEPARATOR.'copy_source_file';
1184+
$targetFilePath = $this->workspace.DIRECTORY_SEPARATOR.'copy_target_file';
11771185

11781186
file_put_contents($sourceFilePath, 'SOURCE FILE');
11791187
chmod($sourceFilePath, 0745);

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,13 @@ public function testTrustedProxies()
15661566
$this->assertEquals(80, $request->getPort());
15671567
$this->assertFalse($request->isSecure());
15681568

1569+
// request is forwarded by a non-trusted proxy
1570+
Request::setTrustedProxies(array('2.2.2.2'));
1571+
$this->assertEquals('3.3.3.3', $request->getClientIp());
1572+
$this->assertEquals('example.com', $request->getHost());
1573+
$this->assertEquals(80, $request->getPort());
1574+
$this->assertFalse($request->isSecure());
1575+
15691576
// trusted proxy via setTrustedProxies()
15701577
Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2'));
15711578
$this->assertEquals('1.1.1.1', $request->getClientIp());

0 commit comments

Comments
 (0)
0