Skip to content

Commit 7aa9c34

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: [SecurityBundle] Optimize dependency injection tests [HttpFoundation] Do not overwrite the Authorization header if it is already set tag for dumped PHP objects must be a local one
2 parents 530ab86 + 7269f74 commit 7aa9c34

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

Inline.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp
105105
return 'null';
106106
case is_object($value):
107107
if ($objectSupport) {
108-
return '!!php/object:'.serialize($value);
108+
return '!php/object:'.serialize($value);
109109
}
110110

111111
if ($exceptionOnInvalidType) {
@@ -469,6 +469,16 @@ private static function evaluateScalar($scalar, $references = array())
469469
return (string) substr($scalar, 5);
470470
case 0 === strpos($scalar, '! '):
471471
return (int) self::parseScalar(substr($scalar, 2));
472+
case 0 === strpos($scalar, '!php/object:'):
473+
if (self::$objectSupport) {
474+
return unserialize(substr($scalar, 12));
475+
}
476+
477+
if (self::$exceptionOnInvalidType) {
478+
throw new ParseException('Object support when parsing a YAML file has been disabled.');
479+
}
480+
481+
return;
472482
case 0 === strpos($scalar, '!!php/object:'):
473483
if (self::$objectSupport) {
474484
return unserialize(substr($scalar, 13));

Tests/DumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function testObjectSupportEnabled()
180180
{
181181
$dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, false, true);
182182

183-
$this->assertEquals('{ foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', $dump, '->dump() is able to dump objects');
183+
$this->assertEquals('{ foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', $dump, '->dump() is able to dump objects');
184184
}
185185

186186
public function testObjectSupportDisabledButNoExceptions()

Tests/ParserTest.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,19 @@ public function testObjectSupportEnabled()
426426
bar: 1
427427
EOF;
428428
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects');
429-
}
430429

431-
public function testObjectSupportDisabledButNoExceptions()
432-
{
433430
$input = <<<EOF
434-
foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
431+
foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
435432
bar: 1
436433
EOF;
434+
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects');
435+
}
437436

437+
/**
438+
* @dataProvider invalidDumpedObjectProvider
439+
*/
440+
public function testObjectSupportDisabledButNoExceptions($input)
441+
{
438442
$this->assertEquals(array('foo' => null, 'bar' => 1), $this->parser->parse($input), '->parse() does not parse objects');
439443
}
440444

@@ -461,11 +465,29 @@ public function testObjectForMapEnabledWithInlineMapping()
461465
}
462466

463467
/**
468+
* @dataProvider invalidDumpedObjectProvider
464469
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
465470
*/
466-
public function testObjectsSupportDisabledWithExceptions()
471+
public function testObjectsSupportDisabledWithExceptions($yaml)
472+
{
473+
$this->parser->parse($yaml, true, false);
474+
}
475+
476+
public function invalidDumpedObjectProvider()
467477
{
468-
$this->parser->parse('foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}', true, false);
478+
$yamlTag = <<<EOF
479+
foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
480+
bar: 1
481+
EOF;
482+
$localTag = <<<EOF
483+
foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
484+
bar: 1
485+
EOF;
486+
487+
return array(
488+
'yaml-tag' => array($yamlTag),
489+
'local-tag' => array($localTag),
490+
);
469491
}
470492

471493
/**

0 commit comments

Comments
 (0)