8000 Merge branch '2.8' into 3.0 · symfony/symfony@897d813 · GitHub
[go: up one dir, main page]

Skip to content

Commit 897d813

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: 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 dc15374 + ef08c07 commit 897d813

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
@@ -72,6 +72,13 @@ public function getEntitiesByIds($identifier, array $values)
7272
$values = array_values(array_filter($values, function ($v) {
7373
return (string) $v === (string) (int) $v;
7474
}));
75+
} elseif ('guid' === $metadata->getTypeOfField($identifier)) {
76+
$parameterType = Connection::PARAM_STR_ARRAY;
77+
78+
// Like above, but we just filter out empty strings.
79+
$values = array_values(array_filter($values, function ($v) {
80+
return (string) $v !== '';
81+
}));
7582
} else {
7683
$parameterType = Connection::PARAM_STR_ARRAY;
7784
}

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

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

431+
public function testObjectNormalizerRegistered()
432+
{
433+
$container = $this->createContainerFromFile('full');
434+
435+
$definition = $container->getDefinition('serializer.normalizer.object');
436+
$tag = $definition->getTag('serializer.normalizer');
437+
438+
$this->assertEquals('Symfony\Component\Serializer\Normalizer\ObjectNormalizer', $definition->getClass());
439+
$this->assertEquals(-1000, $tag[0]['priority']);
440+
}
441+
431442
public function testAssetHelperWhenAssetsAreEnabled()
432443
{
433444
$container = $this->createContainerFromFile('full');

src/Symfony/Component/DomCrawler/Crawler.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,11 @@ public function addHtmlContent($content, $charset = 'UTF-8')
220220
*
221221
* @param string $content The XML content
222222
* @param string $charset The charset
223+
* @param int $options Bitwise OR of the libxml option constants
224+
* LIBXML_PARSEHUGE is dangerous, see
225+
* http://symfony.com/blog/security-release-symfony-2-0-17-released
223226
*/
224-
public function addXmlContent($content, $charset = 'UTF-8')
227+
public function addXmlContent($content, $charset = 'UTF-8', $options = LIBXML_NONET)
225228
{
226229
// remove the default namespace if it's the only namespace to make XPath expressions simpler
227230
if (!preg_match('/xmlns:/', $content)) {
@@ -235,7 +238,7 @@ public function addXmlContent($content, $charset = 'UTF-8')
235238
$dom->validateOnParse = true;
236239

237240
if ('' !== trim($content)) {
238-
@$dom->loadXML($content, LIBXML_NONET | (defined('LIBXML_PARSEHUGE') ? LIBXML_PARSEHUGE : 0));
241+
@$dom->loadXML($content, $options);
239242
}
240243

241244
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()
@@ -1143,8 +1151,8 @@ public function testCopyShouldKeepExecutionPermission()
11431151
{
11441152
$this->markAsSkippedIfChmodIsMissing();
11451153

1146-
$sourceFilePath = $this->workspace . DIRECTORY_SEPARATOR . 'copy_source_file';
1147-
$targetFilePath = $this->workspace . DIRECTORY_SEPARATOR . 'copy_target_file';
1154+
$sourceFilePath = $this->workspace.DIRECTORY_SEPARATOR.'copy_source_file';
1155+
$targetFilePath = $this->workspace.DIRECTORY_SEPARATOR.'copy_target_file';
11481156

11491157
file_put_contents($sourceFilePath, 'SOURCE FILE');
11501158
chmod($sourceFilePath, 0745);

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

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

1591+
// request is forwarded by a non-trusted proxy
1592+
Request::setTrustedProxies(array('2.2.2.2'));
1593+
$this->assertEquals('3.3.3.3', $request->getClientIp());
1594+
$this->assertEquals('example.com', $request->getHost());
1595+
$this->assertEquals(80, $request->getPort());
1596+
$this->assertFalse($request->isSecure());
1597+
15911598
// trusted proxy via setTrustedProxies()
15921599
Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2'));
15931600
$this->assertEquals('1.1.1.1', $request->getClientIp());

0 commit comments

Comments
 (0)
0