Merge branch '3.3' into 3.4

* 3.3:
  Fail as early and noisily as possible
  [FrameworkBundle] Fix visibility of a test helper
  [link] clear the cache after linking
  [link] Prevent warnings when running link with 2.7
  [Validator] ExpressionValidator should use OBJECT_TO_STRING to allow value in message
  do not eagerly filter comment lines
  [WebProfilerBundle], [TwigBundle] Fix Profiler breaking XHTML pages (Content-Type: application/xhtml+xml)
This commit is contained in:
Nicolas Grekas 2017-12-04 13:17:59 +01:00
commit abd76ba4c9
11 changed files with 98 additions and 22 deletions

13
link
View File

@ -35,11 +35,14 @@ if (!is_dir("$argv[1]/vendor/symfony")) {
}
$sfPackages = array('symfony/symfony' => __DIR__);
foreach (glob(__DIR__.'/src/Symfony/{Bundle,Bridge,Component,Component/Security}/*', GLOB_BRACE | GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
$sfPackages[json_decode(file_get_contents("$dir/composer.json"))->name] = $dir;
}
$filesystem = new Filesystem();
foreach (glob(__DIR__.'/src/Symfony/{Bundle,Bridge,Component,Component/Security}/*', GLOB_BRACE | GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
if ($filesystem->exists($composer = "$dir/composer.json")) {
$sfPackages[json_decode(file_get_contents($composer))->name] = $dir;
}
}
foreach (glob("$argv[1]/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
$package = 'symfony/'.basename($dir);
if (is_link($dir)) {
@ -57,3 +60,7 @@ foreach (glob("$argv[1]/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir)
$filesystem->symlink($sfDir, $dir);
echo "\"$package\" has been linked to \"$sfPackages[$package]\".".PHP_EOL;
}
foreach (glob("$argv[1]/var/cache/*") as $cacheDir) {
$filesystem->remove($cacheDir);
}

View File

@ -59,7 +59,12 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? '(del /S /F /Q %s & rmdir %1$s) >nul': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION"));
}
if (extension_loaded('openssl') && ini_get('allow_url_fopen') && !isset($_SERVER['http_proxy']) && !isset($_SERVER['https_proxy'])) {
stream_copy_to_stream(fopen("https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip", 'rb'), fopen("$PHPUNIT_VERSION.zip", 'wb'));
$remoteZip = "https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip";
$remoteZipStream = @fopen($remoteZip, 'rb');
if (!$remoteZipStream) {
throw new \RuntimeException("Could not find $remoteZip");
}
stream_copy_to_stream($remoteZipStream, fopen("$PHPUNIT_VERSION.zip", 'wb'));
} else {
@unlink("$PHPUNIT_VERSION.zip");
passthru("wget https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip");

View File

@ -314,7 +314,7 @@ class RedirectControllerTest extends TestCase
return $controller;
}
public function assertRedirectUrl(Response $returnResponse, $expectedUrl)
private function assertRedirectUrl(Response $returnResponse, $expectedUrl)
{
$this->assertTrue($returnResponse->isRedirect($expectedUrl), "Expected: $expectedUrl\nGot: ".$returnResponse->headers->get('Location'));
}

View File

@ -1,6 +1,6 @@
{# This file is based on WebProfilerBundle/Resources/views/Profiler/base_js.html.twig.
If you make any change in this file, verify the same change is needed in the other file. #}
<script{% if csp_script_nonce is defined and csp_script_nonce %} nonce={{ csp_script_nonce }}{% endif %}>/*<![CDATA[*/
<script{% if csp_script_nonce is defined and csp_script_nonce %} nonce="{{ csp_script_nonce }}"{% endif %}>/*<![CDATA[*/
{# Caution: the contents of this file are processed by Twig before loading
them as JavaScript source code. Always use '/*' comments instead
of '//' comments to avoid impossible-to-debug side-effects #}

View File

@ -1,6 +1,6 @@
{# This file is partially duplicated in TwigBundle/Resources/views/base_js.html.twig. If you
make any change in this file, verify the same change is needed in the other file. #}
<script{% if csp_script_nonce is defined and csp_script_nonce %} nonce={{ csp_script_nonce }}{% endif %}>/*<![CDATA[*/
<script{% if csp_script_nonce is defined and csp_script_nonce %} nonce="{{ csp_script_nonce }}"{% endif %}>/*<![CDATA[*/
{# Caution: the contents of this file are processed by Twig before loading
them as JavaScript source code. Always use '/*' comments instead
of '//' comments to avoid impossible-to-debug side-effects #}

View File

@ -3,7 +3,7 @@
<style{% if csp_style_nonce %} nonce="{{ csp_style_nonce }}"{% endif %}>
{{ include('@WebProfiler/Profiler/toolbar.css.twig', { 'position': position, 'floatable': true }) }}
</style>
<script{% if csp_script_nonce %} nonce={{ csp_script_nonce }}{% endif %}>/*<![CDATA[*/
<script{% if csp_script_nonce %} nonce="{{ csp_script_nonce }}"{% endif %}>/*<![CDATA[*/
(function () {
{% if 'top' == position %}
var sfwdt = document.getElementById('sfwdt{{ token }}');

View File

@ -45,7 +45,7 @@ class ExpressionValidator extends ConstraintValidator
if (!$this->getExpressionLanguage()->evaluate($constraint->expression, $variables)) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setParameter('{{ value }}', $this->formatValue($value, self::OBJECT_TO_STRING))
->setCode(Expression::EXPRESSION_FAILED_ERROR)
->addViolation();
}

View File

@ -15,6 +15,7 @@ use Symfony\Component\Validator\Constraints\Expression;
use Symfony\Component\Validator\Constraints\ExpressionValidator;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
use Symfony\Component\Validator\Tests\Fixtures\Entity;
use Symfony\Component\Validator\Tests\Fixtures\ToString;
class ExpressionValidatorTest extends ConstraintValidatorTestCase
{
@ -87,6 +88,40 @@ class ExpressionValidatorTest extends ConstraintValidatorTestCase
->assertRaised();
}
public function testSucceedingExpressionAtObjectLevelWithToString()
{
$constraint = new Expression('this.data == 1');
$object = new ToString();
$object->data = '1';
$this->setObject($object);
$this->validator->validate($object, $constraint);
$this->assertNoViolation();
}
public function testFailingExpressionAtObjectLevelWithToString()
{
$constraint = new Expression(array(
'expression' => 'this.data == 1',
'message' => 'myMessage',
));
$object = new ToString();
$object->data = '2';
$this->setObject($object);
$this->validator->validate($object, $constraint);
$this->buildViolation('myMessage')
->setParameter('{{ value }}', 'toString')
->setCode(Expression::EXPRESSION_FAILED_ERROR)
->assertRaised();
}
public function testSucceedingExpressionAtPropertyLevel()
{
$constraint = new Expression('value == this.data');

View File

@ -0,0 +1,22 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Validator\Tests\Fixtures;
class ToString
{
public $data;
public function __toString()
{
return 'toString';
}
}

View File

@ -637,21 +637,10 @@ class Parser
continue;
}
// we ignore "comment" lines only when we are not inside a scalar block
if (empty($blockScalarIndentations) && $this->isCurrentLineComment()) {
// remember ignored comment lines (they are used later in nested
// parser calls to determine real line numbers)
//
// CAUTION: beware to not populate the global property here as it
// will otherwise influence the getRealCurrentLineNb() call here
// for consecutive comment lines and subsequent embedded blocks
$this->locallySkippedLineNumbers[] = $this->getRealCurrentLineNb();
continue;
}
if ($indent >= $newIndent) {
$data[] = substr($this->currentLine, $newIndent);
} elseif ($this->isCurrentLineComment()) {
$data[] = $this->currentLine;
} elseif (0 == $indent) {
$this->moveToPreviousLine();

View File

@ -1561,6 +1561,24 @@ YAML;
$this->assertSame(array('foobar' => 'foobar'), $this->parser->parse($yaml));
}
public function testCommentCharactersInMultiLineQuotedStrings()
{
$yaml = <<<YAML
foo:
foobar: 'foo
#bar'
bar: baz
YAML;
$expected = array(
'foo' => array(
'foobar' => 'foo #bar',
'bar' => 'baz',
),
);
$this->assertSame($expected, $this->parser->parse($yaml));
}
public function testParseMultiLineUnquotedString()
{
$yaml = <<<EOT