Merge branch '4.3' into 4.4

* 4.3:
  [FrameworkBundle] Remove project dir from Translator cache vary scanned directories
  [HttpFoundation] Allow redirecting to URLs that contain a semicolon
  catch exceptions when using PDO directly
  [SecurityBundle] fix failing test
This commit is contained in:
Nicolas Grekas 2019-11-17 11:10:42 +01:00
commit 88cf8a7d48
7 changed files with 42 additions and 16 deletions

View File

@ -1234,11 +1234,18 @@ class FrameworkExtension extends Extension
$files[$locale][] = (string) $file;
}
$projectDir = $container->getParameter('kernel.project_dir');
$options = array_merge(
$translator->getArgument(4),
[
'resource_files' => $files,
'scanned_directories' => array_merge($dirs, $nonExistingDirs),
'scanned_directories' => $scannedDirectories = array_merge($dirs, $nonExistingDirs),
'cache_vary' => [
'scanned_directories' => array_map(static function (string $dir) use ($projectDir): string {
return 0 === strpos($dir, $projectDir.'/') ? substr($dir, 1 + \strlen($projectDir)) : $dir;
}, $scannedDirectories),
],
]
);

View File

@ -838,6 +838,8 @@ abstract class FrameworkExtensionTest extends TestCase
);
$this->assertNotEmpty($nonExistingDirectories, 'FrameworkBundle should pass non existing directories to Translator');
$this->assertSame('Fixtures/translations', $options['cache_vary']['scanned_directories'][3]);
}
/**

View File

@ -255,8 +255,10 @@ class TranslatorTest extends TestCase
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
],
],
'scanned_directories' => [
__DIR__.'/../Fixtures/Resources/translations/',
'cache_vary' => [
'scanned_directories' => [
'/Fixtures/Resources/translations/',
],
],
], 'yml');
@ -271,9 +273,11 @@ class TranslatorTest extends TestCase
__DIR__.'/../Fixtures/Resources/translations2/ccc.fr.yml',
],
],
'scanned_directories' => [
__DIR__.'/../Fixtures/Resources/translations/',
__DIR__.'/../Fixtures/Resources/translations2/',
'cache_vary' => [
'scanned_directories' => [
'/Fixtures/Resources/translations/',
'/Fixtures/Resources/translations2/',
],
],
], 'yml');

View File

@ -34,6 +34,7 @@ class Translator extends BaseTranslator implements WarmableInterface
'debug' => false,
'resource_files' => [],
'scanned_directories' => [],
'cache_vary' => [],
];
/**
@ -61,9 +62,10 @@ class Translator extends BaseTranslator implements WarmableInterface
*
* Available options:
*
* * cache_dir: The cache directory (or null to disable caching)
* * debug: Whether to enable debugging or not (false by default)
* * cache_dir: The cache directory (or null to disable caching)
* * debug: Whether to enable debugging or not (false by default)
* * resource_files: List of translation resources available grouped by locale.
* * cache_vary: An array of data that is serialized to generate the cached catalogue name.
*
* @throws InvalidArgumentException
*/
@ -82,9 +84,7 @@ class Translator extends BaseTranslator implements WarmableInterface
$this->resourceFiles = $this->options['resource_files'];
$this->scannedDirectories = $this->options['scanned_directories'];
parent::__construct($defaultLocale, $formatter, $this->options['cache_dir'], $this->options['debug'], [
'scanned_directories' => $this->scannedDirectories,
]);
parent::__construct($defaultLocale, $formatter, $this->options['cache_dir'], $this->options['debug'], $this->options['cache_vary']);
}
/**

View File

@ -160,6 +160,8 @@ trait PdoTrait
$delete = $this->getConnection()->prepare($deleteSql);
} catch (TableNotFoundException $e) {
return true;
} catch (\PDOException $e) {
return true;
}
$delete->bindValue(':time', time(), \PDO::PARAM_INT);
@ -170,6 +172,8 @@ trait PdoTrait
return $delete->execute();
} catch (TableNotFoundException $e) {
return true;
} catch (\PDOException $e) {
return true;
}
}
@ -245,6 +249,7 @@ trait PdoTrait
try {
$conn->exec($sql);
} catch (TableNotFoundException $e) {
} catch (\PDOException $e) {
}
return true;
@ -261,6 +266,7 @@ trait PdoTrait
$stmt = $this->getConnection()->prepare($sql);
$stmt->execute(array_values($ids));
} catch (TableNotFoundException $e) {
} catch (\PDOException $e) {
}
return true;
@ -317,6 +323,11 @@ trait PdoTrait
$this->createTable();
}
$stmt = $conn->prepare($sql);
} catch (\PDOException $e) {
if (!$conn->inTransaction() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
$this->createTable();
}
$stmt = $conn->prepare($sql);
}
if ('sqlsrv' === $driver || 'oci' === $driver) {
@ -351,6 +362,11 @@ trait PdoTrait
$this->createTable();
}
$stmt->execute();
} catch (\PDOException $e) {
if (!$conn->inTransaction() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
$this->createTable();
}
$stmt->execute();
}
if (null === $driver && !$stmt->rowCount()) {
try {

View File

@ -98,7 +98,7 @@ class RedirectResponse extends Response
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="refresh" content="0;url=%1$s" />
<meta http-equiv="refresh" content="0;url=\'%1$s\'" />
<title>Redirecting to %1$s</title>
</head>

View File

@ -20,10 +20,7 @@ class RedirectResponseTest extends TestCase
{
$response = new RedirectResponse('foo.bar');
$this->assertEquals(1, preg_match(
'#<meta http-equiv="refresh" content="\d+;url=foo\.bar" />#',
preg_replace(['/\s+/', '/\'/'], [' ', '"'], $response->getContent())
));
$this->assertRegExp('#<meta http-equiv="refresh" content="\d+;url=\'foo\.bar\'" />#', preg_replace('/\s+/', ' ', $response->getContent()));
}
public function testRedirectResponseConstructorEmptyUrl()