Skip to content

Commit ccbaef9

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: Ability to set empty version strategy in packages CLI: use request context to generate absolute URLs [SecurityBundle] Optimize dependency injection tests Sort bundles in config commands [HttpFoundation] Do not overwrite the Authorization header if it is already set tag for dumped PHP objects must be a local one
2 parents 1548a0a + 7aa9c34 commit ccbaef9

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) {
@@ -479,6 +479,16 @@ private static function evaluateScalar($scalar, $references = array())
479479
return (string) substr($scalar, 5);
480480
case 0 === strpos($scalar, '! '):
481481
return (int) self::parseScalar(substr($scalar, 2));
482+
case 0 === strpos($scalar, '!php/object:'):
483+
if (self::$objectSupport) {
484+
return unserialize(substr($scalar, 12));
485+
}
486+
487+
if (self::$exceptionOnInvalidType) {
488+
throw new ParseException('Object support when parsing a YAML file has been disabled.');
489+
}
490+
491+
return;
482492
case 0 === strpos($scalar, '!!php/object:'):
483493
if (self::$objectSupport) {
484494
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

@@ -470,11 +474,29 @@ public function testObjectForMapIsAppliedAfterParsing()
470474
}
471475

472476
/**
477+
* @dataProvider invalidDumpedObjectProvider
473478
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
474479
*/
475-
public function testObjectsSupportDisabledWithExceptions()
480+
public function testObjectsSupportDisabledWithExceptions($yaml)
481+
{
482+
$this->parser->parse($yaml, true, false);
483+
}
484+
485+
public function invalidDumpedObjectProvider()
476486
{
477-
$this->parser->parse('foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}', true, false);
487+
$yamlTag = <<<EOF
488+
foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
489+
bar: 1
490+
EOF;
491+
$localTag = <<<EOF
492+
foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
493+
bar: 1
494+
EOF;
495+
496+
return array(
497+
'yaml-tag' => array($yamlTag),
498+
'local-tag' => array($localTag),
499+
);
478500
}
479501

480502
/**

0 commit comments

Comments
 (0)